annotate lib-src/make-path.c @ 5604:e9f58d024c3c

Disable ASLR on Mac OS X Lion. 2011-11-27 Marcus Crestani <crestani@informatik.uni-tuebingen.de> * configure.ac: Add "-Wl,-no_pie" to linker flags on Mac OS X Lion to disable ASLR that breaks pdump. * configure: Regenerate.
author Marcus Crestani <crestani@informatik.uni-tuebingen.de>
date Tue, 29 Nov 2011 16:19:53 +0100
parents b9167d522a9a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Make all the directories along a path.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1992 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 438
diff changeset
4 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
6 XEmacs is free software: you can redistribute it and/or modify it
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
7 under the terms of the GNU General Public License as published by the
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
8 Free Software Foundation, either version 3 of the License, or (at your
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
9 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
14 for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5091
diff changeset
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* This program works like mkdir, except that it generates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 intermediate directories if they don't exist. This is just like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 the `mkdir -p' command on most systems; unfortunately, the mkdir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 command on some of the purer BSD systems (like Mt. Xinu) don't have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 that option. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
5091
ed624ab64583 fix compile errors/warnings
Ben Wing <ben@xemacs.org>
parents: 613
diff changeset
27 #ifdef HAVE_CONFIG_H
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
28 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include <sys/stat.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 char *prog_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 static int touchy_mkdir (char *path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 struct stat buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 /* If PATH already exists and is a directory, return success. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 if (stat (path, &buf) >= 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 && (buf.st_mode & S_IFMT) == S_IFDIR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 /* Otherwise, try to make it. If PATH exists but isn't a directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 this will signal an error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 if (mkdir (path, 0777) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 fprintf (stderr, "%s: ", prog_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 perror (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 prog_name = *argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 for (argc--, argv++; argc > 0; argc--, argv++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 char *path = *argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 /* Stop at each slash in path and try to create the directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 Skip any initial slash. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 if (path[i] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 path[i] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 if (touchy_mkdir (path) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 goto next_pathname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 path[i] = '/';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 touchy_mkdir (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 next_pathname:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 }