diff options
Diffstat (limited to 'src/lib/libc/stdlib/getenv.c')
-rw-r--r-- | src/lib/libc/stdlib/getenv.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c index 72367b34e2..5aff11c61a 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.8 2005/08/08 08:05:36 espie Exp $ */ | 1 | /* $OpenBSD: getenv.c,v 1.9 2009/06/03 15:52:16 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. |
@@ -31,7 +31,7 @@ | |||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <string.h> | 32 | #include <string.h> |
33 | 33 | ||
34 | char *__findenv(const char *name, int *offset); | 34 | char *__findenv(const char *name, int len, int *offset); |
35 | 35 | ||
36 | /* | 36 | /* |
37 | * __findenv -- | 37 | * __findenv -- |
@@ -43,18 +43,15 @@ char *__findenv(const char *name, int *offset); | |||
43 | * This routine *should* be a static; don't use it. | 43 | * This routine *should* be a static; don't use it. |
44 | */ | 44 | */ |
45 | char * | 45 | char * |
46 | __findenv(const char *name, int *offset) | 46 | __findenv(const char *name, int len, int *offset) |
47 | { | 47 | { |
48 | extern char **environ; | 48 | extern char **environ; |
49 | int len, i; | 49 | int i; |
50 | const char *np; | 50 | const char *np; |
51 | char **p, *cp; | 51 | char **p, *cp; |
52 | 52 | ||
53 | if (name == NULL || environ == NULL) | 53 | if (name == NULL || environ == NULL) |
54 | return (NULL); | 54 | return (NULL); |
55 | for (np = name; *np && *np != '='; ++np) | ||
56 | ; | ||
57 | len = np - name; | ||
58 | for (p = environ; (cp = *p) != NULL; ++p) { | 55 | for (p = environ; (cp = *p) != NULL; ++p) { |
59 | for (np = name, i = len; i && *cp; i--) | 56 | for (np = name, i = len; i && *cp; i--) |
60 | if (*cp++ != *np++) | 57 | if (*cp++ != *np++) |
@@ -75,6 +72,9 @@ char * | |||
75 | getenv(const char *name) | 72 | getenv(const char *name) |
76 | { | 73 | { |
77 | int offset; | 74 | int offset; |
75 | const char *np; | ||
78 | 76 | ||
79 | return (__findenv(name, &offset)); | 77 | for (np = name; *np && *np != '='; ++np) |
78 | ; | ||
79 | return (__findenv(name, (int)(np - name), &offset)); | ||
80 | } | 80 | } |