X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=utils.c;h=2f935ab83c02b4b326dcdcf491bdc47eeb570ece;hb=bf2ad3a677c948b2bc975a56d444a4f901497894;hp=71fe009076b16390cbef5af1030603b734f25196;hpb=af0aaaa2a3edc0634ebb0a32750df759ab3eb515;p=rrq%2Ffuse_xattrs.git diff --git a/utils.c b/utils.c index 71fe009..2f935ab 100644 --- a/utils.c +++ b/utils.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "utils.h" #include "fuse_xattrs_config.h" @@ -28,6 +29,34 @@ char *prepend_source_directory(const char *b) { return dst; } +int is_directory(const char *path) { + struct stat statbuf; + if (stat(path, &statbuf) != 0) { + fprintf(stderr, "cannot get source directory status: %s\n", path); + return -1; + } + + if (!S_ISDIR(statbuf.st_mode)) { + fprintf(stderr, "source directory must be a directory: %s\n", path); + return -1; + } + + return 1; +} + +int is_regular_file(const char *path) { + struct stat statbuf; + if (stat(path, &statbuf) != 0) { + return -1; + } + + if (!S_ISREG(statbuf.st_mode)) { + return -1; + } + + return 1; +} + char *get_sidecar_path(const char *path) { const size_t path_len = strlen(path);