version 1.4, 1997/06/20 04:54:59 |
version 1.5, 2000/09/15 07:13:48 |
|
|
#include <locale.h> |
#include <locale.h> |
#include <errno.h> |
#include <errno.h> |
|
|
static void usage __P((void)); |
void usage __P((void)); |
|
|
int |
int |
main(argc, argv) |
main(argc, argv) |
|
|
case '-': /* obsolete */ |
case '-': /* obsolete */ |
case 'i': |
case 'i': |
if ((environ = (char **)calloc(1, sizeof(char *))) == NULL) |
if ((environ = (char **)calloc(1, sizeof(char *))) == NULL) |
err(1, "calloc"); |
err(126, "calloc"); |
break; |
break; |
case '?': |
case '?': |
default: |
default: |
|
|
} |
} |
|
|
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) |
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) |
(void)setenv(*argv, ++p, 1); |
if (setenv(*argv, ++p, 1) == -1) { |
|
/* reuse 126, it matches the problem most */ |
|
exit(126); |
|
} |
|
|
if (*argv) { |
if (*argv) { |
/* return 127 if the command to be run could not be found; 126 |
/* |
if the command was was found but could not be invoked */ |
* return 127 if the command to be run could not be |
|
* found; 126 if the command was found but could |
|
* not be invoked |
|
*/ |
execvp(*argv, argv); |
execvp(*argv, argv); |
err((errno == ENOENT) ? 127 : 126, "%s", *argv); |
err((errno == ENOENT) ? 127 : 126, "%s", *argv); |
/* NOTREACHED */ |
/* NOTREACHED */ |
|
|
exit(0); |
exit(0); |
} |
} |
|
|
static void |
void |
usage () |
usage() |
{ |
{ |
(void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n"); |
(void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n"); |
exit (1); |
exit (1); |