diff --git a/src/util.c b/src/util.c index 4b77e9fef5de35ecc74c5dc51730ff4c73e53940..022a6adf4cc5be3a47d53ae8771afb3f8cbb3d59 100644 --- a/src/util.c +++ b/src/util.c @@ -457,6 +457,14 @@ sds getAbsolutePath(char *filename) { return abspath; } +/* Return true if the specified path is just a file basename without any + * relative or absolute path. This function just checks that no / or \ + * character exists inside the specified path, that's enough in the + * environments where Redis runs. */ +int pathIsBaseName(char *path) { + return strchr(path,'/') == NULL && strchr(path,'\\') == NULL; +} + #ifdef UTIL_TEST_MAIN #include diff --git a/src/util.h b/src/util.h index 8e9b0281dd000fb3171c52280acf610bac8693aa..b3667cd6faa03b93a1efe877bd6c9b66232e1059 100644 --- a/src/util.h +++ b/src/util.h @@ -40,5 +40,6 @@ int string2ll(const char *s, size_t slen, long long *value); int string2l(const char *s, size_t slen, long *value); int d2string(char *buf, size_t len, double value); sds getAbsolutePath(char *filename); +int pathIsBaseName(char *path); #endif