summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/getenv.c
diff options
context:
space:
mode:
authormillert <>2009-06-03 15:52:16 +0000
committermillert <>2009-06-03 15:52:16 +0000
commitba53e391e204926a7a71b5a9848b928a56af0062 (patch)
tree27076f4f89f7c81fc3ad7e7b02facdf369d4b2e6 /src/lib/libc/stdlib/getenv.c
parent43170abfbd0c2858c372e7ef19f5dffe4f34137c (diff)
downloadopenbsd-ba53e391e204926a7a71b5a9848b928a56af0062.tar.gz
openbsd-ba53e391e204926a7a71b5a9848b928a56af0062.tar.bz2
openbsd-ba53e391e204926a7a71b5a9848b928a56af0062.zip
Make putenv(), setenv() and unsetenv() standards compliant. The
standard explicitly disallows passing setenv a name with a '=' in it but historic BSD behavior is to allow this but to ignore the '=' and anything after it.
Diffstat (limited to 'src/lib/libc/stdlib/getenv.c')
-rw-r--r--src/lib/libc/stdlib/getenv.c16
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
34char *__findenv(const char *name, int *offset); 34char *__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 */
45char * 45char *
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 *
75getenv(const char *name) 72getenv(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}