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