* add slash-stripper
[citadel.git] / libcitadel / lib / tools.c
index 7d933de1195b9e2d308a40f3e3304ed1ce2f972e..5662133be92854609a719e33d314a85281ad3646 100644 (file)
@@ -456,6 +456,35 @@ char *rfc2047encode(char *line, long length)
        return result;
 }
 
+/*
+ * removes double slashes from pathnames
+ * allows / disallows trailing slashes
+ */
+void StripSlashes(char *Dir, int TrailingSlash)
+{
+       char *a, *b;
+
+       a = b = Dir;
+
+       while (!IsEmptyStr(a)) {
+               if (*a == '/') {
+                       while (*a == '/')
+                               a++;
+                       *b = '/';
+                       b++;
+               }
+               else {
+                       *b = *a;
+                       b++; a++;
+               }
+       }
+       if ((TrailingSlash) && (*(b - 1) != '/')){
+               *b = '/';
+               b++;
+       }
+       *b = '\0';
+
+}
 
 /*
  * Strip leading and trailing spaces from a string