 +    *path_p = '/';
 +  }
 +  /* Replace any '//' with '/' */
-+  path_p = path;
++  path_p = path + !!*path; /* skip first character, if any, to handle UNC paths correctly */
 +  while ((path_p = strstr (path_p, "//")) != NULL)
 +  {
 +    memmove (path_p, path_p + 1, path_size--);

+  size_t in_size = strlen (path);
+  int it_ended_with_a_slash = (path[in_size - 1] == '/') ? 1 : 0;
+  char * result = path;
+  sanitise_path(result);
+  char * result_p = result;
+

index 000000000..c66df924b
--- /dev/null
+++ b/lib/pathtools.c
@@ -0,0 +1,539 @@
+/*
+      .Some useful path tools.
+        .ASCII only for now.
