annotate lib-src/make-path.c @ 229:434959a2fba3 r20-5b13

Import from CVS: tag r20-5b13
author cvs
date Mon, 13 Aug 2007 10:13:02 +0200
parents e45d5e7c476e
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Make all the directories along a path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.28. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* This program works like mkdir, except that it generates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 intermediate directories if they don't exist. This is just like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 the `mkdir -p' command on most systems; unfortunately, the mkdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 command on some of the purer BSD systems (like Mt. Xinu) don't have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 that option. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 175
diff changeset
29 #ifdef emacs
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 175
diff changeset
30 #include <../src/config.h>
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 175
diff changeset
31 #endif
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 175
diff changeset
32
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 char *prog_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 0
diff changeset
42 static int touchy_mkdir (char *path)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 struct stat buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 /* If PATH already exists and is a directory, return success. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 if (stat (path, &buf) >= 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 && (buf.st_mode & S_IFMT) == S_IFDIR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 /* Otherwise, try to make it. If PATH exists but isn't a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 this will signal an error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 if (mkdir (path, 0777) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 fprintf (stderr, "%s: ", prog_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 perror (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 int
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 0
diff changeset
64 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 prog_name = *argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 for (argc--, argv++; argc > 0; argc--, argv++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 char *path = *argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /* Stop at each slash in path and try to create the directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Skip any initial slash. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 if (path[i] == '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 path[i] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if (touchy_mkdir (path) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 goto next_pathname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 path[i] = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 touchy_mkdir (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 next_pathname:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 }