- buf = xstrdup (path);
- parent = dirname (buf);
- status = make_directory (parent, (0777 & ~mask) | 0300,
- FILEUTILS_RECUR);
- free (buf);
+ if (mkdir(path, 0777) < 0) {
+ /* If we failed for any other reason than the directory
+ * already exists, output a diagnostic and return -1.*/
+ if (errno != EEXIST
+ || !(flags & FILEUTILS_RECUR)
+ || (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) {
+ fail_msg = "create";
+ umask(mask);
+ break;
+ }
+ /* Since the directory exists, don't attempt to change
+ * permissions if it was the full target. Note that
+ * this is not an error conditon. */
+ if (!c) {
+ umask(mask);
+ return 0;
+ }
+ }