Changeset 1183 in kBuild for trunk/src/kmk/kmkbuiltin/rm.c
- Timestamp:
- Oct 5, 2007 10:16:46 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/rm.c
r942 r1183 72 72 #endif 73 73 74 #include "kmkbuiltin.h" 75 76 74 77 #ifdef __EMX__ 75 78 #undef S_IFWHT … … 90 93 91 94 static char *argv0; 95 96 static struct option long_options[] = 97 { 98 { "help", no_argument, 0, 261 }, 99 { "version", no_argument, 0, 262 }, 100 { 0, 0, 0, 0 }, 101 }; 102 92 103 93 104 static int check(char *, char *, struct stat *); … … 98 109 static void rm_tree(char **); 99 110 #endif 100 static int usage(void); 111 static int usage(FILE *); 112 113 101 114 102 115 /* … … 108 121 */ 109 122 int 110 kmk_builtin_rm(int argc, char *argv[] )123 kmk_builtin_rm(int argc, char *argv[], char **envp) 111 124 { 112 125 int ch, rflag; 113 char *p; 114 115 /* reinitialize globals */ 116 argv0 = argv[0]; 117 dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0; 118 uid = 0; 119 120 /* kmk: reset getopt and set program name. */ 121 g_progname = argv[0]; 122 opterr = 1; 123 optarg = NULL; 124 optopt = 0; 125 optind = 0; /* init */ 126 127 #if 0 /* kmk: we don't need this */ 128 /* 129 * Test for the special case where the utility is called as 130 * "unlink", for which the functionality provided is greatly 131 * simplified. 132 */ 133 if ((p = rindex(argv[0], '/')) == NULL) 134 p = argv[0]; 135 else 136 ++p; 137 if (strcmp(p, "unlink") == 0) { 138 while (getopt(argc, argv, "") != -1) 139 return usage(); 140 argc -= optind; 141 argv += optind; 142 if (argc != 1) 143 return usage(); 144 rm_file(&argv[0]); 145 return eval; 146 } 147 #else 148 (void)p; 149 #endif 126 127 /* reinitialize globals */ 128 argv0 = argv[0]; 129 dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0; 130 uid = 0; 131 132 /* kmk: reset getopt and set program name. */ 133 g_progname = argv[0]; 134 opterr = 1; 135 optarg = NULL; 136 optopt = 0; 137 optind = 0; /* init */ 138 150 139 Pflag = rflag = 0; 151 while ((ch = getopt (argc, argv, "dfiPRrvW")) != -1)140 while ((ch = getopt_long(argc, argv, "dfiPRrvW", long_options, NULL)) != -1) 152 141 switch(ch) { 153 142 case 'd': … … 182 171 break; 183 172 #endif 173 case 261: 174 usage(stdout); 175 return 0; 176 case 262: 177 return kbuild_version(argv[0]); 178 case '?': 184 179 default: 185 return usage( );180 return usage(stderr); 186 181 } 187 182 argc -= optind; … … 191 186 if (fflag) 192 187 return (0); 193 return usage( );188 return usage(stderr); 194 189 } 195 190 … … 603 598 604 599 static int 605 usage( void)606 { 607 608 (void)fprintf(stderr, "%s\n%s\n",609 "usage: rm [-f | -i] [-dPRrvW] file ...\n",610 " unlink file");600 usage(FILE *pf) 601 { 602 fprintf(pf, "usage: %s [-f | -i] [-dPRrvW] file ...\n" 603 " or: %s --help\n" 604 " or: %s --version\n", 605 g_progname, g_progname, g_progname); 611 606 return EX_USAGE; 612 607 }
Note:
See TracChangeset
for help on using the changeset viewer.