Commit | Line | Data |
---|---|---|
22e155fc | 1 | /* |
a19bfa91 KB |
2 | * Copyright (c) 1987, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
35901a68 | 4 | * |
6d936b27 | 5 | * %sccs.include.redist.c% |
22e155fc DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
a19bfa91 KB |
9 | static char copyright[] = |
10 | "@(#) Copyright (c) 1987, 1993\n\ | |
11 | The Regents of the University of California. All rights reserved.\n"; | |
35901a68 | 12 | #endif /* not lint */ |
22e155fc DF |
13 | |
14 | #ifndef lint | |
bf3186a8 | 15 | static char sccsid[] = "@(#)printenv.c 8.2 (Berkeley) %G%"; |
35901a68 | 16 | #endif /* not lint */ |
22e155fc | 17 | |
d726c894 KB |
18 | #include <sys/types.h> |
19 | ||
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
bf3186a8 | 23 | #include <unistd.h> |
d726c894 KB |
24 | |
25 | void usage __P((void)); | |
26 | ||
18745775 BJ |
27 | /* |
28 | * printenv | |
29 | * | |
30 | * Bill Joy, UCB | |
31 | * February, 1979 | |
32 | */ | |
d726c894 | 33 | int |
18745775 BJ |
34 | main(argc, argv) |
35 | int argc; | |
d726c894 | 36 | char *argv[]; |
18745775 | 37 | { |
35901a68 KB |
38 | extern char **environ; |
39 | register char *cp, **ep; | |
d726c894 KB |
40 | register size_t len; |
41 | int ch; | |
42 | ||
43 | while ((ch = getopt(argc, argv, "")) != EOF) | |
44 | switch(ch) { | |
45 | case '?': | |
46 | default: | |
47 | usage(); | |
48 | } | |
49 | argc -= optind; | |
50 | argv += optind; | |
18745775 | 51 | |
d726c894 | 52 | if (argc == 0) { |
18745775 | 53 | for (ep = environ; *ep; ep++) |
d726c894 | 54 | (void)printf("%s\n", *ep); |
35901a68 KB |
55 | exit(0); |
56 | } | |
d726c894 | 57 | len = strlen(*argv); |
35901a68 | 58 | for (ep = environ; *ep; ep++) |
d726c894 | 59 | if (!memcmp(*ep, *argv, len)) { |
35901a68 KB |
60 | cp = *ep + len; |
61 | if (!*cp || *cp == '=') { | |
d726c894 | 62 | (void)printf("%s\n", *cp ? cp + 1 : cp); |
35901a68 | 63 | exit(0); |
18745775 | 64 | } |
35901a68 KB |
65 | } |
66 | exit(1); | |
18745775 | 67 | } |
d726c894 KB |
68 | |
69 | void | |
70 | usage() | |
71 | { | |
72 | (void)fprintf(stderr, "usage: printenv [name]\n"); | |
73 | exit(1); | |
74 | } |