pathIsBaseName() added to utils.c

The function is used to test that the specified string looks like just
as the basename of a path, without any absolute or relative path.
This commit is contained in:
antirez
2013-07-02 12:24:08 +02:00
parent 028fdbb70b
commit 25a3ad7f74
2 changed files with 9 additions and 0 deletions
+8
View File
@@ -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 <assert.h>
+1
View File
@@ -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