summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/setenv.c')
-rw-r--r--src/lib/libc/stdlib/setenv.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c
index a36669888d..044f01b1c9 100644
--- a/src/lib/libc/stdlib/setenv.c
+++ b/src/lib/libc/stdlib/setenv.c
@@ -32,13 +32,14 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)setenv.c 5.6 (Berkeley) 6/4/91";*/ 35static char *rcsid = "$OpenBSD: setenv.c,v 1.5 2002/12/10 22:44:13 mickey Exp $";
36static 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 */ 36#endif /* LIBC_SCCS and not lint */
38 37
39#include <stdlib.h> 38#include <stdlib.h>
40#include <string.h> 39#include <string.h>
41 40
41char *__findenv(const char *name, int *offset);
42
42/* 43/*
43 * setenv -- 44 * setenv --
44 * Set the value of the environmental variable "name" to be 45 * Set the value of the environmental variable "name" to be
@@ -54,7 +55,6 @@ setenv(name, value, rewrite)
54 static int alloced; /* if allocated space before */ 55 static int alloced; /* if allocated space before */
55 register char *C; 56 register char *C;
56 int l_value, offset; 57 int l_value, offset;
57 char *__findenv();
58 58
59 if (*value == '=') /* no `=' in value */ 59 if (*value == '=') /* no `=' in value */
60 ++value; 60 ++value;
@@ -63,7 +63,8 @@ setenv(name, value, rewrite)
63 if (!rewrite) 63 if (!rewrite)
64 return (0); 64 return (0);
65 if (strlen(C) >= l_value) { /* old larger; copy over */ 65 if (strlen(C) >= l_value) { /* old larger; copy over */
66 while (*C++ = *value++); 66 while ((*C++ = *value++))
67 ;
67 return (0); 68 return (0);
68 } 69 }
69 } else { /* create new slot */ 70 } else { /* create new slot */
@@ -72,10 +73,11 @@ setenv(name, value, rewrite)
72 73
73 for (P = environ, cnt = 0; *P; ++P, ++cnt); 74 for (P = environ, cnt = 0; *P; ++P, ++cnt);
74 if (alloced) { /* just increase size */ 75 if (alloced) { /* just increase size */
75 environ = (char **)realloc((char *)environ, 76 P = (char **)realloc((void *)environ,
76 (size_t)(sizeof(char *) * (cnt + 2))); 77 (size_t)(sizeof(char *) * (cnt + 2)));
77 if (!environ) 78 if (!P)
78 return (-1); 79 return (-1);
80 environ = P;
79 } 81 }
80 else { /* get new space */ 82 else { /* get new space */
81 alloced = 1; /* copy old entries into it */ 83 alloced = 1; /* copy old entries into it */
@@ -95,7 +97,7 @@ setenv(name, value, rewrite)
95 return (-1); 97 return (-1);
96 for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) 98 for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
97 ; 99 ;
98 for (*C++ = '='; *C++ = *value++; ) 100 for (*C++ = '='; (*C++ = *value++); )
99 ; 101 ;
100 return (0); 102 return (0);
101} 103}