Changeset 1705 for trunk/src/kmk/kmkbuiltin/chmod.c
- Timestamp:
- Sep 2, 2008, 5:17:42 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/chmod.c
r1704 r1705 39 39 #endif /* not lint */ 40 40 #endif 41 #include <sys/cdefs.h> 42 __FBSDID("$FreeBSD: src/bin/chmod/chmod.c,v 1.33 2005/01/10 08:39:20 imp Exp $"); 41 /*#include <sys/cdefs.h> */ 42 /*__FBSDID("$FreeBSD: src/bin/chmod/chmod.c,v 1.33 2005/01/10 08:39:20 imp 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 <fts.h> … … 52 52 #include <stdlib.h> 53 53 #include <string.h> 54 #include <unistd.h> 55 56 void usage(void); 54 #ifndef _MSC_VER 55 # include <unistd.h> 56 #else 57 # include "mscfakes.h" 58 #endif 59 #include "getopt.h" 60 #include "kmkbuiltin.h" 61 62 #if defined(__APPLE__) && !defined(_DARWIN_FEATURE_UNIX_CONFORMANCE) 63 extern int lchmod(const char *, mode_t); 64 #endif 65 66 static int usage(FILE *); 67 68 static struct option long_options[] = 69 { 70 { "help", no_argument, 0, 261 }, 71 { "version", no_argument, 0, 262 }, 72 { 0, 0, 0, 0 }, 73 }; 74 57 75 58 76 int 59 main(int argc, char *argv[])77 kmk_builtin_chmod(int argc, char *argv[], char **envp) 60 78 { 61 79 FTS *ftsp; … … 68 86 int (*change_mode)(const char *, mode_t); 69 87 88 /* kmk: reset getopt and set progname */ 89 g_progname = argv[0]; 90 opterr = 1; 91 optarg = NULL; 92 optopt = 0; 93 optind = 0; /* init */ 94 70 95 set = NULL; 71 96 Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; 72 while ((ch = getopt (argc, argv, "HLPRXfghorstuvwx")) != -1)97 while ((ch = getopt_long(argc, argv, "HLPRXfghorstuvwx", long_options, NULL)) != -1) 73 98 switch (ch) { 74 99 case 'H': … … 116 141 vflag++; 117 142 break; 143 case 261: 144 usage(stdout); 145 return 0; 146 case 262: 147 return kbuild_version(argv[0]); 118 148 case '?': 119 149 default: 120 usage();150 return usage(stderr); 121 151 } 122 152 done: argv += optind; … … 124 154 125 155 if (argc < 2) 126 usage();156 return usage(stderr); 127 157 128 158 if (Rflag) { 129 159 fts_options = FTS_PHYSICAL; 130 160 if (hflag) 131 errx(1,161 return errx(1, 132 162 "the -R and -h options may not be specified together."); 133 163 if (Hflag) … … 147 177 mode = *argv; 148 178 if ((set = setmode(mode)) == NULL) 149 errx(1, "invalid file mode: %s", mode);179 return errx(1, "invalid file mode: %s", mode); 150 180 151 181 if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL) 152 err(1, "fts_open");182 return err(1, "fts_open"); 153 183 for (rval = 0; (p = fts_read(ftsp)) != NULL;) { 154 184 switch (p->fts_info) { … … 208 238 } 209 239 if (errno) 210 err(1, "fts_read");240 rval = err(1, "fts_read"); 211 241 free(set); 212 exit(rval); 242 fts_close(ftsp); 243 return rval; 213 244 } 214 245 215 void 216 usage( void)246 int 247 usage(FILE *out) 217 248 { 218 (void)fprintf(stderr, 219 "usage: chmod [-fhv] [-R [-H | -L | -P]] mode file ...\n"); 220 exit(1); 249 (void)fprintf(out, 250 "usage: %s [-fhv] [-R [-H | -L | -P]] mode file ...\n" 251 " or: %s --version\n" 252 " or: %s --help\n", 253 g_progname, g_progname, g_progname); 254 255 return 1; 221 256 }
Note:
See TracChangeset
for help on using the changeset viewer.