aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/make-path.c
diff options
context:
space:
mode:
authorRichard M. Stallman1994-09-24 01:48:04 +0000
committerRichard M. Stallman1994-09-24 01:48:04 +0000
commitcc162c53060d953c67e44939c4c77364f27f0c4b (patch)
tree5b031b21256c9235b7dace6edbea3bb339ffaba9 /lib-src/make-path.c
parentc24e1160ff40c156e0d0a7b9f7ab89587bd11111 (diff)
downloademacs-cc162c53060d953c67e44939c4c77364f27f0c4b.tar.gz
emacs-cc162c53060d953c67e44939c4c77364f27f0c4b.zip
(touchy_mkdir): Make dir ugo+re even if it isn't new.
Rename path to dirname.
Diffstat (limited to 'lib-src/make-path.c')
-rw-r--r--lib-src/make-path.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/lib-src/make-path.c b/lib-src/make-path.c
index 00597d8719a..c4e5bf93144 100644
--- a/lib-src/make-path.c
+++ b/lib-src/make-path.c
@@ -32,24 +32,42 @@ extern int errno;
32 32
33char *prog_name; 33char *prog_name;
34 34
35int touchy_mkdir (path) 35/* Create directory DIRNAME if it does not exist already.
36 char *path; 36 Then give permission for everyone to read and search it.
37 Return 0 if successful, 1 if not. */
38
39int
40touchy_mkdir (dirname)
41 char *dirname;
37{ 42{
38 struct stat buf; 43 struct stat buf;
39 44
40 /* If PATH already exists and is a directory, return success. */ 45 /* If DIRNAME already exists and is a directory, don't create. */
41 if (stat (path, &buf) >= 0 46 if (! (stat (dirname, &buf) >= 0
42 && (buf.st_mode & S_IFMT) == S_IFDIR) 47 && (buf.st_mode & S_IFMT) == S_IFDIR))
43 return 0; 48 {
49 /* Otherwise, try to make it. If DIRNAME exists but isn't a directory,
50 this will signal an error. */
51 if (mkdir (dirname, 0777) < 0)
52 {
53 fprintf (stderr, "%s: ", prog_name);
54 perror (dirname);
55 return 1;
56 }
57 }
44 58
45 /* Otherwise, try to make it. If PATH exists but isn't a directory, 59 /* Make sure everyone can look at this directory. */
46 this will signal an error. */ 60 if (stat (dirname, &buf) < 0)
47 if (mkdir (path, 0777) < 0)
48 { 61 {
49 fprintf (stderr, "%s: ", prog_name); 62 fprintf (stderr, "%s: ", prog_name);
50 perror (path); 63 perror (dirname);
51 return 1; 64 return 1;
52 } 65 }
66 if (chmod (dirname, 0555 | (buf.st_mode & 0777)) < 0)
67 {
68 fprintf (stderr, "%s: ", prog_name);
69 perror (dirname);
70 }
53 71
54 return 0; 72 return 0;
55} 73}
@@ -63,23 +81,23 @@ main (argc, argv)
63 81
64 for (argc--, argv++; argc > 0; argc--, argv++) 82 for (argc--, argv++; argc > 0; argc--, argv++)
65 { 83 {
66 char *path = *argv; 84 char *dirname = *argv;
67 int i; 85 int i;
68 86
69 /* Stop at each slash in path and try to create the directory. 87 /* Stop at each slash in dirname and try to create the directory.
70 Skip any initial slash. */ 88 Skip any initial slash. */
71 for (i = (path[0] == '/') ? 1 : 0; path[i]; i++) 89 for (i = (dirname[0] == '/') ? 1 : 0; dirname[i]; i++)
72 if (path[i] == '/') 90 if (dirname[i] == '/')
73 { 91 {
74 path[i] = '\0'; 92 dirname[i] = '\0';
75 if (touchy_mkdir (path) < 0) 93 if (touchy_mkdir (dirname) < 0)
76 goto next_pathname; 94 goto next_dirname;
77 path[i] = '/'; 95 dirname[i] = '/';
78 } 96 }
79 97
80 touchy_mkdir (path); 98 touchy_mkdir (dirname);
81 99
82 next_pathname: 100 next_dirname:
83 ; 101 ;
84 } 102 }
85 103