- /* If PATH already exists and is a directory, return success. */
- if (stat (path, &buf) >= 0
- && (buf.st_mode & S_IFMT) == S_IFDIR)
- return 0;
+ /* If DIRNAME already exists and is a directory, don't create. */
+ if (! (stat (dirname, &buf) >= 0
+ && (buf.st_mode & S_IFMT) == S_IFDIR))
+ {
+ /* Otherwise, try to make it. If DIRNAME exists but isn't a directory,
+ this will signal an error. */
+ if (mkdir (dirname, 0777) < 0)
+ {
+ fprintf (stderr, "%s: ", prog_name);
+ perror (dirname);
+ return 1;
+ }
+ }