Changeset 370 for trunk/src/gmake/kmkbuiltin/rm.c
- Timestamp:
- Dec 18, 2005, 4:48:02 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/rm.c
r341 r370 38 38 static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94"; 39 39 #endif /* not lint */ 40 #endif41 40 #include <sys/cdefs.h> 42 41 //__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.47 2004/04/06 20:06:50 markm Exp $"); 42 #endif 43 43 44 44 #include <sys/stat.h> 45 #ifndef _MSC_VER 45 46 #include <sys/param.h> 46 47 #include <sys/mount.h> 47 48 #include <err.h> 48 #endif 49 50 #include "err.h" 49 51 #include <errno.h> 50 52 #include <fcntl.h> 53 #ifdef DO_RMTREE 51 54 #include <fts.h> 55 #endif 56 #ifndef _MSC_VER 52 57 #include <grp.h> 53 58 #include <pwd.h> 59 #endif 54 60 #include <stdio.h> 55 61 #include <stdlib.h> 56 62 #include <string.h> 63 #ifndef _MSC_VER 57 64 #include <sysexits.h> 58 65 #include <unistd.h> 66 #else 67 #include "mscfakes.h" 68 #endif 59 69 60 70 #ifdef __EMX__ … … 81 91 static void rm_file(char **); 82 92 static int rm_overwrite(char *, struct stat *); 93 #ifdef DO_RMTREE 83 94 static void rm_tree(char **); 95 #endif 84 96 static int usage(void); 85 97 … … 100 112 dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0; 101 113 uid = 0; 114 /* kmk: reset getopt and set program name. */ 115 g_progname = argv[0]; 102 116 opterr = 1; 103 117 optarg = NULL; … … 110 124 #endif 111 125 126 #if 0 /* kmk: we don't need this */ 112 127 /* 113 128 * Test for the special case where the utility is called as … … 129 144 return eval; 130 145 } 131 146 #else 147 (void)p; 148 #endif 132 149 Pflag = rflag = 0; 133 150 while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1) … … 149 166 case 'R': 150 167 case 'r': /* Compatibility. */ 168 #ifdef DO_RMTREE 151 169 rflag = 1; 152 170 break; 171 #else 172 errno = EINVAL; 173 return err(1, "Recursion is not supported!"); 174 #endif 153 175 case 'v': 154 176 vflag = 1; … … 176 198 if (*argv) { 177 199 stdin_ok = isatty(STDIN_FILENO); 178 200 #ifdef DO_RMTREE 179 201 if (rflag) 180 202 rm_tree(argv); 181 203 else 204 #endif 182 205 rm_file(argv); 183 206 } … … 186 209 } 187 210 211 #ifdef DO_RMTREE 188 212 static void 189 213 rm_tree(char **argv) … … 214 238 flags |= FTS_WHITEOUT; 215 239 #endif 216 if (!(fts = fts_open(argv, flags, NULL))) 217 err(1, "fts_open"); 240 if (!(fts = fts_open(argv, flags, NULL))) { 241 eval = err(1, "fts_open"); 242 return; 243 } 218 244 while ((p = fts_read(fts)) != NULL) { 219 245 switch (p->fts_info) { … … 226 252 continue; 227 253 case FTS_ERR: 228 errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno)); 254 eval = errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno)); 255 return; 229 256 case FTS_NS: 230 257 /* … … 318 345 continue; 319 346 rval = unlink(p->fts_accpath); 347 #ifdef _MSC_VER 348 if (rval != 0) { 349 chmod(p->fts_accpath, 0777); 350 rval = unlink(p->fts_accpath); 351 } 352 #endif 353 320 354 if (rval == 0 || (fflag && errno == ENOENT)) { 321 355 if (rval == 0 && vflag) … … 335 369 } 336 370 } 371 #endif /* DO_RMTREE */ 337 372 338 373 static void … … 395 430 continue; 396 431 rval = unlink(f); 432 #ifdef _MSC_VER 433 if (rval != 0) { 434 chmod(f, 0777); 435 rval = unlink(f); 436 } 437 #endif 397 438 } 398 439 } … … 448 489 #endif 449 490 if ((buf = malloc(bsize)) == NULL) 450 e rr(1, "%s: malloc", file);491 exit(err(1, "%s: malloc", file)); 451 492 452 493 #define PASS(byte) { \ … … 512 553 #ifdef SF_APPEND 513 554 if ((flagsp = fflagstostr(sp->st_flags)) == NULL) 514 e rr(1, "fflagstostr");555 exit(err(1, "fflagstostr")); 515 556 (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ", 516 557 modep + 1, modep[9] == ' ' ? "" : " ", … … 521 562 free(flagsp); 522 563 #else 564 (void)flagsp; 523 565 (void)fprintf(stderr, "override %s%s %d/%d for %s? ", 524 566 modep + 1, modep[9] == ' ' ? "" : " ",
Note:
See TracChangeset
for help on using the changeset viewer.