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