+/* TODO: re-use memory to avoid calling malloc every time */
+char *prepend_source_directory(const char *b) {
+ const size_t b_size = strlen(b);
+ const size_t dst_len = xattrs_config.source_dir_size + b_size + 1;
+ char *dst = (char*) malloc(sizeof(char) * dst_len);
+
+ memcpy(dst, xattrs_config.source_dir, xattrs_config.source_dir_size);
+ memcpy(dst+xattrs_config.source_dir_size, b, b_size + 1); // include '\0'
+ //sprintf(dst, "%s%s", a, 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;
+}