comparison lib-src/make-path.c @ 9050:953e5ea2b8ea

(touchy_mkdir): Make dir ugo+re even if it isn't new. Rename path to dirname.
author Richard M. Stallman <rms@gnu.org>
date Sat, 24 Sep 1994 01:48:04 +0000
parents b3ea9bc60744
children
comparison
equal deleted inserted replaced
9049:522a9e03ca05 9050:953e5ea2b8ea
30 30
31 extern int errno; 31 extern int errno;
32 32
33 char *prog_name; 33 char *prog_name;
34 34
35 int 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
39 int
40 touchy_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;
65 }
66 if (chmod (dirname, 0555 | (buf.st_mode & 0777)) < 0)
67 {
68 fprintf (stderr, "%s: ", prog_name);
69 perror (dirname);
52 } 70 }
53 71
54 return 0; 72 return 0;
55 } 73 }
56 74
61 { 79 {
62 prog_name = *argv; 80 prog_name = *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
86 return 0; 104 return 0;
87 } 105 }