From 6978aeb3bf2c44bdfe2422847a52f22d61ed034b Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Tue, 2 Jul 2013 12:08:07 +0200
Subject: [PATCH] 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.
---
 src/util.c | 8 ++++++++
 src/util.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/src/util.c b/src/util.c
index 4b77e9fef..022a6adf4 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 <assert.h>
 
diff --git a/src/util.h b/src/util.h
index 8e9b0281d..b3667cd6f 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