+ int newly_created_dir = 1;
+
+ /* slash points to the leftmost unprocessed component of dirpath. */
+ basename_dir = slash;
+
+ slash = strchr (slash, '/');
+ if (slash == NULL)
+ break;
+
+ /* If we're *not* doing chdir before each mkdir, then we have to refer
+ to the target using the full (multi-component) directory name. */
+ if (!do_chdir)
+ basename_dir = dirpath;
+
+ /* The mkdir and stat calls below appear to be reversed.
+ They are not. It is important to call mkdir first and then to
+ call stat (to distinguish the three cases) only if mkdir fails.
+ The alternative to this approach is to `stat' each directory,
+ then to call mkdir if it doesn't exist. But if some other process
+ were to create the directory between the stat & mkdir, the mkdir
+ would fail with EEXIST. */
+