remove eprintf.c -- not used in current <assert.h>
[unix-history] / usr / src / lib / libc / stdlib / getenv.c
CommitLineData
535b4307
KB
1/*
2 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved.
4 *
019bea33 5 * %sccs.include.redist.c%
535b4307
KB
6 */
7
2ce81398 8#if defined(LIBC_SCCS) && !defined(lint)
f0a345ab 9static char sccsid[] = "@(#)getenv.c 5.8 (Berkeley) %G%";
535b4307 10#endif /* LIBC_SCCS and not lint */
b8f253e8 11
6a46fa84
KB
12#include <stdlib.h>
13#include <stddef.h>
f0a345ab 14#include <string.h>
834cc75f 15
24f434cb 16/*
535b4307 17 * getenv --
834cc75f 18 * Returns ptr to value associated with name, if any, else NULL.
24f434cb 19 */
24f434cb
BJ
20char *
21getenv(name)
f0a345ab 22 const char *name;
24f434cb 23{
535b4307
KB
24 int offset;
25 char *_findenv();
24f434cb 26
535b4307 27 return(_findenv(name, &offset));
24f434cb
BJ
28}
29
30/*
535b4307 31 * _findenv --
834cc75f
KB
32 * Returns pointer to value associated with name, if any, else NULL.
33 * Sets offset to be the offset of the name/value combination in the
34 * environmental array, for use by setenv(3) and unsetenv(3).
35 * Explicitly removes '=' in argument name.
36 *
37 * This routine *should* be a static; don't use it.
24f434cb 38 */
834cc75f 39char *
535b4307 40_findenv(name, offset)
834cc75f 41 register char *name;
535b4307 42 int *offset;
24f434cb 43{
535b4307
KB
44 extern char **environ;
45 register int len;
46 register char **P, *C;
24f434cb 47
535b4307
KB
48 for (C = name, len = 0; *C && *C != '='; ++C, ++len);
49 for (P = environ; *P; ++P)
50 if (!strncmp(*P, name, len))
834cc75f
KB
51 if (*(C = *P + len) == '=') {
52 *offset = P - environ;
53 return(++C);
54 }
24f434cb
BJ
55 return(NULL);
56}