2023-12-21 21:56:36 +00:00
|
|
|
#include "libfileis.h"
|
|
|
|
|
2023-12-18 07:09:33 +00:00
|
|
|
#include <unistd.h> /* access(3), F_OK, R_OK, W_OK, X_OK */
|
|
|
|
|
2023-12-21 21:55:00 +00:00
|
|
|
int f_executable(char *path){ return access(path, X_OK) == 0; } /* test -x */
|
|
|
|
int f_exists(char *path){ return access(path, F_OK) == 0; } /* test -e */
|
|
|
|
int f_readable(char *path){ return access(path, R_OK) == 0; } /* test -r */
|
|
|
|
int f_writeable(char *path){ return access(path, W_OK) == 0; } /* test -w */
|
|
|
|
|
|
|
|
#include <sys/stat.h> /* lstat(3), struct stat, S_ISBLK, S_ISCHR, S_ISDIR,
|
|
|
|
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
2023-12-21 21:56:36 +00:00
|
|
|
* S_ISUID, S_ISVTX */
|
2023-12-21 21:55:00 +00:00
|
|
|
|
|
|
|
static struct stat buf;
|
|
|
|
|
|
|
|
int f_blockspecial(char *path){ /* test -b */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISBLK(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_charspecial(char *path){ /* test -c */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISCHR(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_directory(char *path){ /* test -d */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISDIR(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_fifospecial(char *path){ /* test -p */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISFIFO(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_gid(char *path){ /* test -g */
|
|
|
|
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISGID);
|
|
|
|
}
|
|
|
|
int f_regular(char *path){ /* test -f */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISREG(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_socket(char *path){ /* test -S */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISSOCK(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_sticky(char *path){ /* test -k */
|
|
|
|
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISVTX);
|
|
|
|
}
|
|
|
|
int f_symlink(char *path){ /* test -h; test -L */
|
|
|
|
return lstat(path, &buf) != -1 && S_ISLNK(buf.st_mode);
|
|
|
|
}
|
|
|
|
int f_uid(char *path){ /* test -u */
|
|
|
|
return lstat(path, &buf) != -1 && (buf.st_mode & S_ISUID);
|
|
|
|
}
|