forked from tinylcy/vino
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.c
47 lines (42 loc) · 1.34 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <sys/stat.h>
/*-------------------------------------------------------*
check whether the request resource is a directory.
-------------------------------------------------------*/
int is_directory(const char *filepath) {
struct stat info;
if(stat(filepath, &info) == 0 && S_ISDIR(info.st_mode)) {
return 1;
}
return 0;
}
/*-------------------------------------------------------*
check if a file is executable.
-------------------------------------------------------*/
int is_executable(const char *filepath) {
struct stat info;
return (stat(filepath, &info) == 0 && S_ISREG(info.st_mode) && (S_IXUSR & info.st_mode));
}
/*-------------------------------------------------------*
check if a file is readable.
-------------------------------------------------------*/
int is_readable(const char *filepath) {
struct stat info;
return ((stat(filepath, &info) == 0) && S_ISREG(info.st_mode) && (S_IRUSR & info.st_mode));
}
/*-------------------------------------------------------*
check if a file exists.
-------------------------------------------------------*/
int file_exist(const char *filepath) {
struct stat info;
return (stat(filepath, &info) == 0);
}
char *contains(char *start, char *end, char target) {
char *p = NULL;
for(p = start; p <= end; p++) {
if(*p == target) {
return p;
}
}
return NULL;
}