]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/uxmisc.c
Implement deferred closing of Windows handle-sockets.
[PuTTY.git] / unix / uxmisc.c
index a7a2fcb93576bf7248a409757458a41fdbe0b827..daa61a0193665909755938231c0d10a84ce703ba 100644 (file)
@@ -322,3 +322,30 @@ char *make_dir_and_check_ours(const char *dirname)
 
     return NULL;
 }
+
+char *make_dir_path(const char *path, mode_t mode)
+{
+    int pos = 0;
+    char *prefix;
+
+    while (1) {
+        pos += strcspn(path + pos, "/");
+
+        if (pos > 0) {
+            prefix = dupprintf("%.*s", pos, path);
+
+            if (mkdir(prefix, mode) < 0 && errno != EEXIST) {
+                char *ret = dupprintf("%s: mkdir: %s",
+                                      prefix, strerror(errno));
+                sfree(prefix);
+                return ret;
+            }
+
+            sfree(prefix);
+        }
+
+        if (!path[pos])
+            return NULL;
+        pos += strspn(path + pos, "/");
+    }
+}