- /* First check the common case: directory already exists. */
- if (stat (path, &st) == 0)
- return S_ISDIR (st.st_mode) ? TRUE : FALSE;
-
- for (start = path; *start != '\0'; start = end + 1) {
- /* start points to the first unprocessed character.
- * Find the next slash from start onwards. */
- end = strchr (start, '/');
-
- /* If there are no more slashes then all the parent directories
- * have been made. Now attempt to make the whole path. */
- if (end == NULL)
- return make_directory (path, mode);
-
- /* Make the path up to the next slash, unless the current
- * directory component is actually empty. */
- if (end > start) {
- *end = '\0';
- ret = make_directory (path, mode);
- *end = '/';
- if (! ret)
- return FALSE;
+ /* mkdir parents, if any */
+ slash = strrchr (path, '/');
+ if (slash && slash != path) {
+ parent = talloc_strndup (ctx, path, slash - path);
+ if (! parent) {
+ fprintf (stderr, "Error: %s\n", strerror (ENOMEM));
+ return FALSE;