Changeset 227 in kBuild for trunk/src/gmake/kmkbuiltin
- Timestamp:
- Feb 9, 2005 10:21:34 AM (20 years ago)
- Location:
- trunk/src/gmake/kmkbuiltin
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/mkdir.c
r226 r227 40 40 #endif 41 41 #include <sys/cdefs.h> 42 __FBSDID("$FreeBSD: src/bin/mkdir/mkdir.c,v 1.28 2004/04/06 20:06:48 markm Exp $");42 //__FBSDID("$FreeBSD: src/bin/mkdir/mkdir.c,v 1.28 2004/04/06 20:06:48 markm Exp $"); 43 43 44 44 #include <sys/types.h> 45 45 #include <sys/stat.h> 46 46 47 #include <err.h>47 //#include <err.h> 48 48 #include <errno.h> 49 49 #include <libgen.h> … … 54 54 #include <unistd.h> 55 55 56 extern void * setmode(const char *p); 57 extern mode_t getmode(const void *bbox, mode_t omode); 58 56 59 static int build(char *, mode_t); 57 static voidusage(void);60 static int usage(void); 58 61 59 62 int vflag; 60 63 61 64 int 62 main(int argc, char *argv[])65 kmk_builtin_mkdir(int argc, char *argv[]) 63 66 { 64 67 int ch, exitval, success, pflag; … … 68 71 omode = pflag = 0; 69 72 mode = NULL; 73 opterr = 1; 74 optarg = NULL; 75 optopt = 0; 76 optind = 0; /* init */ 70 77 while ((ch = getopt(argc, argv, "m:pv")) != -1) 71 78 switch(ch) { … … 80 87 break; 81 88 case '?': 82 83 usage();89 default: 90 return usage(); 84 91 } 85 92 … … 87 94 argv += optind; 88 95 if (argv[0] == NULL) 89 usage();96 return usage(); 90 97 91 98 if (mode == NULL) { 92 99 omode = S_IRWXU | S_IRWXG | S_IRWXO; 93 100 } else { 94 if ((set = setmode(mode)) == NULL) 95 errx(1, "invalid file mode: %s", mode); 101 if ((set = setmode(mode)) == NULL) { 102 fprintf(stderr, "%s: invalid file mode: %s", mode, argv[0]); 103 return 1; 104 } 96 105 omode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO); 97 106 free(set); … … 105 114 } else if (mkdir(*argv, omode) < 0) { 106 115 if (errno == ENOTDIR || errno == ENOENT) 107 warn("%s", dirname(*argv));116 fprintf(stderr, "%s: %s", argv[0], dirname(*argv)); 108 117 else 109 warn("%s", *argv);118 fprintf(stderr, "%s: %s", argv[0], *argv); 110 119 success = 0; 111 120 } else if (vflag) … … 122 131 */ 123 132 if (success && mode != NULL && chmod(*argv, omode) == -1) { 124 warn("%s", *argv);133 fprintf(stderr, "%s: %s", argv[0], *argv); 125 134 exitval = 1; 126 135 } 127 136 } 128 exit(exitval);137 return exitval; 129 138 } 130 139 … … 200 209 } 201 210 202 void 211 int 203 212 usage(void) 204 213 { 205 214 206 215 (void)fprintf(stderr, "usage: mkdir [-pv] [-m mode] directory ...\n"); 207 exit (EX_USAGE);216 return EX_USAGE; 208 217 }
Note:
See TracChangeset
for help on using the changeset viewer.