diff options
-rw-r--r-- | index.c | 22 | ||||
-rw-r--r-- | index.h | 1 |
2 files changed, 23 insertions, 0 deletions
@@ -1,6 +1,7 @@ #include <stddef.h> #include <stdint.h> #include <stdlib.h> +#include <sys/stat.h> #include "index.h" #include "macros.h" @@ -96,3 +97,24 @@ char *index_to_str(index *idx) { return NULL; } } + +int index_path_exists(index *idx, const char *root, char **path) { + char *dummy; + path = (path != NULL) ? path : &dummy; + for (int i = 0; i < 2; ++i) { + struct stat st; + *path = make_index_path(root, idx, i); + /* Does the index path exist? */ + if (*path != NULL && stat(*path, &st) == 0) { + if (path == &dummy) { + free(*path); + *path = NULL; + } + return 1; + } else { + free(*path); + *path = NULL; + } + } + return 0; +} @@ -17,5 +17,6 @@ struct index { extern int is_valid_index(index *idx); extern char *make_index_path(const char *root, index *idx, int path_type); extern char *index_to_str(index *idx); +extern int index_path_exists(index *idx, const char *root, char **path); #endif |