X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/4aa1632a5f5c533d235ab51fd27636928f29bf89..f3d6f4eefcf665b2dfd78ac2beff5a7fcea7c16a:/lib-src/make-path.c diff --git a/lib-src/make-path.c b/lib-src/make-path.c index 6741aa34b9..c4e5bf9314 100644 --- a/lib-src/make-path.c +++ b/lib-src/make-path.c @@ -5,7 +5,7 @@ This file is part of GNU Emacs. GNU Emacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) +the Free Software Foundation; either version 2, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, @@ -32,23 +32,41 @@ 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); - return -1; + 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,25 @@ 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: ; } + + return 0; }