Changeset 2074 in kBuild for trunk/src/kmk
- Timestamp:
- Nov 17, 2008 2:55:56 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/redirect.c
r2019 r2074 66 66 { 67 67 fprintf(pOut, 68 "usage: %s [-[rwa+tb]<fd> <file>] [- E <var=val>] [-C <dir>] -- <program> [args]\n"68 "usage: %s [-[rwa+tb]<fd> <file>] [-c<fd>] [-Z] [-E <var=val>] [-C <dir>] -- <program> [args]\n" 69 69 " or: %s --help\n" 70 70 " or: %s --version\n" … … 75 75 " o = stdout\n" 76 76 " e = stderr\n" 77 "\n" 78 "The -c switch will close the specified file descriptor.\n" 79 "\n" 80 "The -Z switch zaps the environment.\n" 77 81 "\n" 78 82 "The -E switch is for making changes to the environment in a putenv\n" … … 92 96 93 97 94 int main(int argc, char **argv )98 int main(int argc, char **argv, char **envp) 95 99 { 96 100 int i; … … 132 136 else if (!strcmp(psz, "-chdir")) 133 137 psz = "C"; 138 else if (!strcmp(psz, "-zap-env")) 139 psz = "Z"; 140 else if (!strcmp(psz, "-close")) 141 psz = "c"; 134 142 } 135 143 … … 237 245 fprintf(pStdErr, "%s: error: chdir(\"%s\"): %s\n", name(argv[0]), psz, strerror(errno)); 238 246 return 1; 247 } 248 249 /* 250 * Zap environment switch? 251 * This is a bit of a hack. 252 */ 253 if (*psz == 'Z') 254 { 255 unsigned i = 0; 256 while (envp[i] != NULL) 257 i++; 258 while (i-- > 0) 259 { 260 char *pszEqual = strchr(envp[i], '='); 261 char *pszCopy; 262 263 if (pszEqual) 264 *pszEqual = '\0'; 265 pszCopy = strdup(envp[i]); 266 if (pszEqual) 267 *pszEqual = '='; 268 269 #if defined(_MSC_VER) || defined(__OS2__) 270 putenv(pszCopy); 271 #else 272 unsetenv(pszCopy); 273 #endif 274 free(pszCopy); 275 } 276 continue; 277 } 278 279 /* 280 * Close the specified file descriptor (no stderr/out/in aliases). 281 */ 282 if (*psz == 'c') 283 { 284 psz++; 285 if (!*psz) 286 { 287 i++; 288 if (i >= argc) 289 { 290 fprintf(pStdErr, "%s: syntax error: missing filename argument.\n", name(argv[0])); 291 return 1; 292 } 293 psz = argv[i]; 294 } 295 296 fd = (int)strtol(psz, &psz, 0); 297 if (!fd || *psz) 298 { 299 fprintf(pStdErr, "%s: error: failed to convert '%s' to a number\n", name(argv[0]), argv[i]); 300 return 1; 301 302 } 303 if (fd < 0) 304 { 305 fprintf(pStdErr, "%s: error: negative fd %d (%s)\n", name(argv[0]), fd, argv[i]); 306 return 1; 307 } 308 /** @todo deal with stderr */ 309 close(fd); 310 continue; 239 311 } 240 312
Note:
See TracChangeset
for help on using the changeset viewer.