diff options
Diffstat (limited to 'src/lib/libc/stdlib/setenv.c')
-rw-r--r-- | src/lib/libc/stdlib/setenv.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index a36669888d..2ba072b65c 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/lib/libc/stdlib/setenv.c | |||
@@ -10,11 +10,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | 14 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 15 | * without specific prior written permission. |
20 | * | 16 | * |
@@ -32,13 +28,14 @@ | |||
32 | */ | 28 | */ |
33 | 29 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | /*static char *sccsid = "from: @(#)setenv.c 5.6 (Berkeley) 6/4/91";*/ | 31 | static char *rcsid = "$OpenBSD: setenv.c,v 1.6 2003/06/02 20:18:38 millert Exp $"; |
36 | static char *rcsid = "$Id: setenv.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
38 | 33 | ||
39 | #include <stdlib.h> | 34 | #include <stdlib.h> |
40 | #include <string.h> | 35 | #include <string.h> |
41 | 36 | ||
37 | char *__findenv(const char *name, int *offset); | ||
38 | |||
42 | /* | 39 | /* |
43 | * setenv -- | 40 | * setenv -- |
44 | * Set the value of the environmental variable "name" to be | 41 | * Set the value of the environmental variable "name" to be |
@@ -54,7 +51,6 @@ setenv(name, value, rewrite) | |||
54 | static int alloced; /* if allocated space before */ | 51 | static int alloced; /* if allocated space before */ |
55 | register char *C; | 52 | register char *C; |
56 | int l_value, offset; | 53 | int l_value, offset; |
57 | char *__findenv(); | ||
58 | 54 | ||
59 | if (*value == '=') /* no `=' in value */ | 55 | if (*value == '=') /* no `=' in value */ |
60 | ++value; | 56 | ++value; |
@@ -63,7 +59,8 @@ setenv(name, value, rewrite) | |||
63 | if (!rewrite) | 59 | if (!rewrite) |
64 | return (0); | 60 | return (0); |
65 | if (strlen(C) >= l_value) { /* old larger; copy over */ | 61 | if (strlen(C) >= l_value) { /* old larger; copy over */ |
66 | while (*C++ = *value++); | 62 | while ((*C++ = *value++)) |
63 | ; | ||
67 | return (0); | 64 | return (0); |
68 | } | 65 | } |
69 | } else { /* create new slot */ | 66 | } else { /* create new slot */ |
@@ -72,10 +69,11 @@ setenv(name, value, rewrite) | |||
72 | 69 | ||
73 | for (P = environ, cnt = 0; *P; ++P, ++cnt); | 70 | for (P = environ, cnt = 0; *P; ++P, ++cnt); |
74 | if (alloced) { /* just increase size */ | 71 | if (alloced) { /* just increase size */ |
75 | environ = (char **)realloc((char *)environ, | 72 | P = (char **)realloc((void *)environ, |
76 | (size_t)(sizeof(char *) * (cnt + 2))); | 73 | (size_t)(sizeof(char *) * (cnt + 2))); |
77 | if (!environ) | 74 | if (!P) |
78 | return (-1); | 75 | return (-1); |
76 | environ = P; | ||
79 | } | 77 | } |
80 | else { /* get new space */ | 78 | else { /* get new space */ |
81 | alloced = 1; /* copy old entries into it */ | 79 | alloced = 1; /* copy old entries into it */ |
@@ -95,7 +93,7 @@ setenv(name, value, rewrite) | |||
95 | return (-1); | 93 | return (-1); |
96 | for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) | 94 | for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) |
97 | ; | 95 | ; |
98 | for (*C++ = '='; *C++ = *value++; ) | 96 | for (*C++ = '='; (*C++ = *value++); ) |
99 | ; | 97 | ; |
100 | return (0); | 98 | return (0); |
101 | } | 99 | } |