summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/getenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/getenv.c')
-rw-r--r--src/lib/libc/stdlib/getenv.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c
index 5aff11c61a..fd8482e9e3 100644
--- a/src/lib/libc/stdlib/getenv.c
+++ b/src/lib/libc/stdlib/getenv.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getenv.c,v 1.9 2009/06/03 15:52:16 millert Exp $ */ 1/* $OpenBSD: getenv.c,v 1.10 2010/08/23 22:31:50 millert Exp $ */
2/* 2/*
3 * Copyright (c) 1987, 1993 3 * Copyright (c) 1987, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -36,8 +36,9 @@ char *__findenv(const char *name, int len, int *offset);
36/* 36/*
37 * __findenv -- 37 * __findenv --
38 * Returns pointer to value associated with name, if any, else NULL. 38 * Returns pointer to value associated with name, if any, else NULL.
39 * Starts searching within the environmental array at offset.
39 * Sets offset to be the offset of the name/value combination in the 40 * Sets offset to be the offset of the name/value combination in the
40 * environmental array, for use by setenv(3) and unsetenv(3). 41 * environmental array, for use by putenv(3), setenv(3) and unsetenv(3).
41 * Explicitly removes '=' in argument name. 42 * Explicitly removes '=' in argument name.
42 * 43 *
43 * This routine *should* be a static; don't use it. 44 * This routine *should* be a static; don't use it.
@@ -52,7 +53,7 @@ __findenv(const char *name, int len, int *offset)
52 53
53 if (name == NULL || environ == NULL) 54 if (name == NULL || environ == NULL)
54 return (NULL); 55 return (NULL);
55 for (p = environ; (cp = *p) != NULL; ++p) { 56 for (p = environ + *offset; (cp = *p) != NULL; ++p) {
56 for (np = name, i = len; i && *cp; i--) 57 for (np = name, i = len; i && *cp; i--)
57 if (*cp++ != *np++) 58 if (*cp++ != *np++)
58 break; 59 break;
@@ -71,7 +72,7 @@ __findenv(const char *name, int len, int *offset)
71char * 72char *
72getenv(const char *name) 73getenv(const char *name)
73{ 74{
74 int offset; 75 int offset = 0;
75 const char *np; 76 const char *np;
76 77
77 for (np = name; *np && *np != '='; ++np) 78 for (np = name; *np && *np != '='; ++np)