Mercurial > hg > xemacs-beta
comparison lib-src/make-path.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 15872534500d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 /* Make all the directories along a path. | |
2 Copyright (C) 1992 Free Software Foundation, Inc. | |
3 | |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs 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 2, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs 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. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Synched up with: FSF 19.28. */ | |
22 | |
23 /* This program works like mkdir, except that it generates | |
24 intermediate directories if they don't exist. This is just like | |
25 the `mkdir -p' command on most systems; unfortunately, the mkdir | |
26 command on some of the purer BSD systems (like Mt. Xinu) don't have | |
27 that option. */ | |
28 | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 #include <stdio.h> | |
32 #include <errno.h> | |
33 | |
34 #ifdef emacs | |
35 #include <config.h> | |
36 #endif | |
37 | |
38 extern int errno; | |
39 | |
40 char *prog_name; | |
41 | |
42 static int touchy_mkdir (path) | |
43 char *path; | |
44 { | |
45 struct stat buf; | |
46 | |
47 /* If PATH already exists and is a directory, return success. */ | |
48 if (stat (path, &buf) >= 0 | |
49 && (buf.st_mode & S_IFMT) == S_IFDIR) | |
50 return 0; | |
51 | |
52 /* Otherwise, try to make it. If PATH exists but isn't a directory, | |
53 this will signal an error. */ | |
54 if (mkdir (path, 0777) < 0) | |
55 { | |
56 fprintf (stderr, "%s: ", prog_name); | |
57 perror (path); | |
58 return 1; | |
59 } | |
60 | |
61 return 0; | |
62 } | |
63 | |
64 int | |
65 main (argc, argv) | |
66 int argc; | |
67 char **argv; | |
68 { | |
69 prog_name = *argv; | |
70 | |
71 for (argc--, argv++; argc > 0; argc--, argv++) | |
72 { | |
73 char *path = *argv; | |
74 int i; | |
75 | |
76 /* Stop at each slash in path and try to create the directory. | |
77 Skip any initial slash. */ | |
78 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++) | |
79 if (path[i] == '/') | |
80 { | |
81 path[i] = '\0'; | |
82 if (touchy_mkdir (path) < 0) | |
83 goto next_pathname; | |
84 path[i] = '/'; | |
85 } | |
86 | |
87 touchy_mkdir (path); | |
88 | |
89 next_pathname: | |
90 ; | |
91 } | |
92 | |
93 return 0; | |
94 } |