don't bother resolving onbld python module deps
[unleashed.git] / bin / env / env.c
blob574c3b43a299c01ee5d5cfbb7e233a6539428ae5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
26 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
31 * All Rights Reserved
35 * env [ - ] [ name=value ]... [command arg...]
36 * set environment, then execute command (or print environment)
37 * - says start fresh, otherwise merge with inherited environment
40 #include <stdio.h>
41 #include <string.h>
42 #include <stdlib.h>
43 #include <errno.h>
44 #include <unistd.h>
45 #include <limits.h>
46 #include <ctype.h>
47 #include <locale.h>
48 #include <string.h>
49 #include <unistd.h>
52 static void Usage();
53 extern char **environ;
56 int
57 main(int argc, char **argv)
59 char **p;
60 int opt;
61 int i;
64 (void) setlocale(LC_ALL, "");
66 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
67 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
68 #endif
69 (void) textdomain(TEXT_DOMAIN);
71 /* check for non-standard "-" option */
72 if ((argc > 1) && (strcmp(argv[1], "-")) == 0) {
73 (void) clearenv();
74 for (i = 1; i < argc; i++)
75 argv[i] = argv[i+1];
76 argc--;
79 /* get options */
80 while ((opt = getopt(argc, argv, "i")) != EOF) {
81 switch (opt) {
82 case 'i':
83 (void) clearenv();
84 break;
86 default:
87 Usage();
91 /* get environment strings */
92 while (argv[optind] != NULL && strchr(argv[optind], '=') != NULL) {
93 if (putenv(argv[optind])) {
94 (void) perror(argv[optind]);
95 exit(1);
97 optind++;
100 /* if no utility, output environment strings */
101 if (argv[optind] == NULL) {
102 p = environ;
103 while (*p != NULL)
104 (void) puts(*p++);
105 } else {
106 (void) execvp(argv[optind], &argv[optind]);
107 (void) fprintf(stderr, "%s: %s: %s\n", argv[0], argv[optind],
108 strerror(errno));
109 exit(((errno == ENOENT) || (errno == ENOTDIR)) ? 127 : 126);
111 return (0);
115 static void
116 Usage()
118 (void) fprintf(stderr, gettext(
119 "Usage: env [-i] [name=value ...] [utility [argument ...]]\n"
120 " env [-] [name=value ...] [utility [argument ...]]\n"));
121 exit(1);