From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/mkdirs.c | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/mkdirs.c (limited to 'reference/C/CONTRIB/SNIP/mkdirs.c') 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 +#include +#include +#ifdef __TURBOC__ + #include +#else + #include +#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 */ -- cgit v1.2.3-54-g00ecf