summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/mkdirs.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/CONTRIB/SNIP/mkdirs.c')
-rwxr-xr-xreference/C/CONTRIB/SNIP/mkdirs.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/SNIP/mkdirs.c b/reference/C/CONTRIB/SNIP/mkdirs.c
new file mode 100755
index 0000000..b9228e4
--- /dev/null
+++ b/reference/C/CONTRIB/SNIP/mkdirs.c
@@ -0,0 +1,52 @@
+/*
+** MKDIRS.C - Function to build multi-level directories in a single call
+**
+** Original Copyright 1993 by Bob Stout as part of
+** the MicroFirm Function Library (MFL)
+**
+** This subset version is hereby donated to the public domain.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef __TURBOC__
+ #include <dir.h>
+#else
+ #include <direct.h>
+#endif
+
+int mkdirs(char *path)
+{
+ int retval;
+
+ while (0 != (retval = mkdir(path)))
+ {
+ char subpath[FILENAME_MAX] = "", *delim;
+
+ if (NULL == (delim = strrchr(path, '\\')))
+ return retval;
+ strncat(subpath, path, delim - path); /* Appends NUL */
+ mkdirs(subpath);
+ }
+ return retval;
+}
+
+#ifdef TEST
+
+main(int argc, char *argv[])
+{
+ if (2 > argc)
+ {
+ puts("Usage: MKDIRS pathname [...pathname]");
+ return -1;
+ }
+ while (--argc)
+ {
+ ++argv;
+ printf("mkdirs(%s) returned %d\n", *argv, mkdirs(*argv));
+ }
+ return 0;
+}
+
+#endif /* TEST */