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>
38 static int touchy_mkdir(char *path)
42 /* If PATH already exists and is a directory, return success. */
43 if (stat(path, &buf) >= 0 && (buf.st_mode & S_IFMT) == S_IFDIR)
46 /* Otherwise, try to make it. If PATH exists but isn't a directory,
47 this will signal an error. */
48 if (mkdir(path, 0777) < 0) {
49 fprintf(stderr, "%s: ", prog_name);
57 int main(int argc, char *argv[])
61 for (argc--, argv++; argc > 0; argc--, argv++) {
65 /* Stop at each slash in path and try to create the directory.
66 Skip any initial slash. */
67 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++)
70 if (touchy_mkdir(path) < 0)