aboutsummaryrefslogtreecommitdiffstats
path: root/src/path.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/path.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index e9031100d..71bacd7b3 100644
--- a/src/path.c
+++ b/src/path.c
@@ -20,6 +20,7 @@
#include "log.h"
#include "charConv.h"
#include "conf.h"
+#include "utf8.h"
#include <stdlib.h>
#include <string.h>
@@ -202,3 +203,41 @@ char * parentPath(char * path) {
return parentPath;
}
+
+char * sanitizePathDup(char * path) {
+ int len = strlen(path)+1;
+ char * ret = malloc(len);
+ char * cp = ret;
+
+ memset(ret,0,len);
+
+ len = 0;
+
+ /* illeminate more than one '/' in a row, like "///" */
+ while(*path) {
+ while(*path=='/') path++;
+ if(*path=='.') {
+ /* we dont want to have hidden directoires, or '.' or
+ ".." in our path */
+ free(ret);
+ return NULL;
+ }
+ while(*path && *path!='/') {
+ *(cp++) = *(path++);
+ len++;
+ }
+ if(*path=='/') {
+ *(cp++) = *(path++);
+ len++;
+ }
+ }
+
+ if(len && ret[len-1]=='/') {
+ len--;
+ ret[len] = '\0';
+ }
+
+ printf("sanitized: %s\n", ret);
+
+ return realloc(ret,len+1);
+}