diff options
author | Richard M. Stallman <rms@gnu.org> | 1994-09-24 01:48:04 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1994-09-24 01:48:04 +0000 |
commit | 80b2ff3530f84cd1ce2ed5e175540ef1b2f2e84e (patch) | |
tree | 4f968e12f62c0c88cf4c99d6c216ab5c113c16e1 /lib-src | |
parent | 5c0e6573c60a7560227e03d545c73c6068517714 (diff) | |
download | emacs-80b2ff3530f84cd1ce2ed5e175540ef1b2f2e84e.tar.gz |
(touchy_mkdir): Make dir ugo+re even if it isn't new.
Rename path to dirname.
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/make-path.c | 58 |
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; char *prog_name; -int touchy_mkdir (path) - char *path; +/* Create directory DIRNAME if it does not exist already. + Then give permission for everyone to read and search it. + Return 0 if successful, 1 if not. */ + +int +touchy_mkdir (dirname) + char *dirname; { struct stat buf; - /* If PATH already exists and is a directory, return success. */ - if (stat (path, &buf) >= 0 - && (buf.st_mode & S_IFMT) == S_IFDIR) - return 0; + /* If DIRNAME already exists and is a directory, don't create. */ + if (! (stat (dirname, &buf) >= 0 + && (buf.st_mode & S_IFMT) == S_IFDIR)) + { + /* Otherwise, try to make it. If DIRNAME exists but isn't a directory, + this will signal an error. */ + if (mkdir (dirname, 0777) < 0) + { + fprintf (stderr, "%s: ", prog_name); + perror (dirname); + return 1; + } + } - /* Otherwise, try to make it. If PATH exists but isn't a directory, - this will signal an error. */ - if (mkdir (path, 0777) < 0) + /* Make sure everyone can look at this directory. */ + if (stat (dirname, &buf) < 0) { fprintf (stderr, "%s: ", prog_name); - perror (path); + perror (dirname); return 1; } + if (chmod (dirname, 0555 | (buf.st_mode & 0777)) < 0) + { + fprintf (stderr, "%s: ", prog_name); + perror (dirname); + } return 0; } @@ -63,23 +81,23 @@ main (argc, argv) for (argc--, argv++; argc > 0; argc--, argv++) { - char *path = *argv; + char *dirname = *argv; int i; - /* Stop at each slash in path and try to create the directory. + /* Stop at each slash in dirname and try to create the directory. Skip any initial slash. */ - for (i = (path[0] == '/') ? 1 : 0; path[i]; i++) - if (path[i] == '/') + for (i = (dirname[0] == '/') ? 1 : 0; dirname[i]; i++) + if (dirname[i] == '/') { - path[i] = '\0'; - if (touchy_mkdir (path) < 0) - goto next_pathname; - path[i] = '/'; + dirname[i] = '\0'; + if (touchy_mkdir (dirname) < 0) + goto next_dirname; + dirname[i] = '/'; } - touchy_mkdir (path); + touchy_mkdir (dirname); - next_pathname: + next_dirname: ; } |