Changeset 601 for trunk/src/gmake/kmkbuiltin/rmdir.c
- Timestamp:
- Nov 26, 2006, 1:19:19 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/rmdir.c
r598 r601 39 39 #endif /* not lint */ 40 40 #endif 41 #if 0 41 42 #include <sys/cdefs.h> 42 43 __FBSDID("$FreeBSD: src/bin/rmdir/rmdir.c,v 1.20 2005/01/26 06:51:28 ssouhlal Exp $"); 44 #endif 43 45 44 #include <err.h>46 #include "err.h" 45 47 #include <stdio.h> 46 48 #include <stdlib.h> 47 49 #include <string.h> 50 #ifndef _MSC_VER 48 51 #include <unistd.h> 52 #else 53 #include <malloc.h> 54 #include "mscfakes.h" 55 #endif 49 56 50 static int rm_path(c har *);51 static voidusage(void);57 static int rm_path(const char *); 58 static int usage(void); 52 59 53 60 static int pflag; … … 55 62 56 63 int 57 main(int argc, char *argv[])64 kmk_builtin_rmdir(int argc, char *argv[]) 58 65 { 59 66 int ch, errors; 60 67 68 /* reinitialize globals */ 69 vflag = 0; 70 71 /* kmk: reset getopt and set progname */ 72 g_progname = argv[0]; 73 opterr = 1; 74 optarg = NULL; 75 optopt = 0; 76 #if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__) 77 optreset = 1; 78 optind = 1; 79 #else 80 optind = 0; /* init */ 81 #endif 61 82 while ((ch = getopt(argc, argv, "pv")) != -1) 62 83 switch(ch) { … … 69 90 case '?': 70 91 default: 71 usage();92 return usage(); 72 93 } 73 94 argc -= optind; … … 75 96 76 97 if (argc == 0) 77 usage();98 return usage(); 78 99 79 100 for (errors = 0; *argv; argv++) { … … 89 110 } 90 111 91 exit(errors);112 return errors; 92 113 } 93 114 … … 96 117 { 97 118 char *p; 119 const size_t len = strlen(path); 120 p = alloca(len + 1); 121 path = memcpy(p, path, len + 1); 98 122 99 p = path + strlen(path); 123 #if defined(_MSC_VER) || defined(__EMX__) 124 p = strchr(path, '\\'); 125 while (p) { 126 *p++ = '/'; 127 p = strchr(p, '\\'); 128 } 129 #endif 130 131 p = path + len; 100 132 while (--p > path && *p == '/') 101 133 ; … … 108 140 if (p == path) 109 141 break; 142 #if defined(_MSC_VER) || defined(__EMX__) 143 if (p[-1] == ':' && p - 2 == path) 144 break; 145 #endif 110 146 111 147 if (rmdir(path) < 0) { … … 120 156 } 121 157 122 static void158 static int 123 159 usage(void) 124 160 { 125 161 126 162 (void)fprintf(stderr, "usage: rmdir [-pv] directory ...\n"); 127 exit(1);163 return 1; 128 164 }
Note:
See TracChangeset
for help on using the changeset viewer.