1 /* Make all the directories along a path.
2 Copyright (C) 1992 Free Software Foundation, Inc.
4 This file is part of SXEmacs.
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Synched up with: FSF 19.28. */
21 /* This program works like mkdir, except that it generates
22 intermediate directories if they don't exist. This is just like
23 the `mkdir -p' command on most systems; unfortunately, the mkdir
24 command on some of the purer BSD systems (like Mt. Xinu) don't have
31 #include <sys/types.h>
39 static int touchy_mkdir(char *path)
43 /* Try to make it. If PATH exists, EEXIST will be the
44 return. Anyway on error but isn't a directory,
45 this will signal an error. */
46 if (mkdir(path, 0777) < 0 && errno != EEXIST ) {
47 int serrno = errno; /* save errno because stat may
50 /* If PATH already exists and is a directory, return success. */
51 if (stat(path, &buf) >= 0 && (buf.st_mode & S_IFMT) == S_IFDIR)
54 fprintf(stderr, "%s: %s", prog_name, strerror(serrno));
61 int main(int argc, char *argv[])
65 for (argc--, argv++; argc > 0; argc--, argv++) {
69 /* Stop at each slash in path and try to create the directory.
70 Skip any initial slash. */
71 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++)
74 if (touchy_mkdir(path) < 0)