source: trunk/third/sysinfo/getenv.c @ 12269

Revision 12269, 1.4 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12268, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (c) 1992-1998 Michael A. Cooper.
3 * This software may be freely used and distributed provided it is not
4 * sold for profit or used in part or in whole for commercial gain
5 * without prior written agreement, and the author is credited
6 * appropriately.
7 */
8
9#if defined(LIBC_SCCS) && !defined(lint)
10static char sccsid[] = "@(#)getenv.c    5.8 (Berkeley) 2/23/91";
11static char rcsid[] = "$Revision: 1.1.1.2 $";
12#endif /* LIBC_SCCS and not lint */
13
14#include <stdlib.h>
15#include <stddef.h>
16#include <string.h>
17
18#if     defined(notdef)
19/*
20 * getenv --
21 *      Returns ptr to value associated with name, if any, else NULL.
22 */
23char *
24getenv(name)
25        const char *name;
26{
27        int offset;
28        char *_findenv();
29
30        return(_findenv(name, &offset));
31}
32#endif  /* notdef */
33
34/*
35 * _findenv --
36 *      Returns pointer to value associated with name, if any, else NULL.
37 *      Sets offset to be the offset of the name/value combination in the
38 *      environmental array, for use by setenv(3) and unsetenv(3).
39 *      Explicitly removes '=' in argument name.
40 *
41 *      This routine *should* be a static; don't use it.
42 */
43char *
44_findenv(name, offset)
45        register char *name;
46        int *offset;
47{
48        extern char **environ;
49        register int len;
50        register char **P, *C;
51
52        for (C = name, len = 0; *C && *C != '='; ++C, ++len);
53        for (P = environ; *P; ++P)
54                if (!strncmp(*P, name, len))
55                        if (*(C = *P + len) == '=') {
56                                *offset = P - environ;
57                                return(++C);
58                        }
59        return(NULL);
60}
Note: See TracBrowser for help on using the repository browser.