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 | |
a19bfa91 | 15 | static char sccsid[] = "@(#)printenv.c 8.1 (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> | |
23 | ||
24 | void usage __P((void)); | |
25 | ||
18745775 BJ |
26 | /* |
27 | * printenv | |
28 | * | |
29 | * Bill Joy, UCB | |
30 | * February, 1979 | |
31 | */ | |
d726c894 | 32 | int |
18745775 BJ |
33 | main(argc, argv) |
34 | int argc; | |
d726c894 | 35 | char *argv[]; |
18745775 | 36 | { |
35901a68 KB |
37 | extern char **environ; |
38 | register char *cp, **ep; | |
d726c894 KB |
39 | register size_t len; |
40 | int ch; | |
41 | ||
42 | while ((ch = getopt(argc, argv, "")) != EOF) | |
43 | switch(ch) { | |
44 | case '?': | |
45 | default: | |
46 | usage(); | |
47 | } | |
48 | argc -= optind; | |
49 | argv += optind; | |
18745775 | 50 | |
d726c894 | 51 | if (argc == 0) { |
18745775 | 52 | for (ep = environ; *ep; ep++) |
d726c894 | 53 | (void)printf("%s\n", *ep); |
35901a68 KB |
54 | exit(0); |
55 | } | |
d726c894 | 56 | len = strlen(*argv); |
35901a68 | 57 | for (ep = environ; *ep; ep++) |
d726c894 | 58 | if (!memcmp(*ep, *argv, len)) { |
35901a68 KB |
59 | cp = *ep + len; |
60 | if (!*cp || *cp == '=') { | |
d726c894 | 61 | (void)printf("%s\n", *cp ? cp + 1 : cp); |
35901a68 | 62 | exit(0); |
18745775 | 63 | } |
35901a68 KB |
64 | } |
65 | exit(1); | |
18745775 | 66 | } |
d726c894 KB |
67 | |
68 | void | |
69 | usage() | |
70 | { | |
71 | (void)fprintf(stderr, "usage: printenv [name]\n"); | |
72 | exit(1); | |
73 | } |