Permalink
Browse files

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.
  • Loading branch information...
antirez committed Jul 2, 2013
1 parent 028fdbb commit 25a3ad7f7477e99bc101827b0ac80336889c4c64
Showing with 9 additions and 0 deletions.
  1. +8 −0 src/util.c
  2. +1 −0 src/util.h
View
@@ -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>
View
@@ -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

0 comments on commit 25a3ad7

Please sign in to comment.