]> git.saurik.com Git - apple/libc.git/blob - stdlib/FreeBSD/setenv.c.patch
Libc-320.1.3.tar.gz
[apple/libc.git] / stdlib / FreeBSD / setenv.c.patch
1 --- setenv.c.orig Mon Apr 28 16:37:26 2003
2 +++ setenv.c Tue May 6 16:55:50 2003
3 @@ -40,6 +40,7 @@
4 #include <stddef.h>
5 #include <stdlib.h>
6 #include <string.h>
7 +#include <crt_externs.h>
8
9 char *__findenv(const char *, int *);
10
11 @@ -54,7 +55,7 @@
12 const char *value;
13 int rewrite;
14 {
15 - extern char **environ;
16 + char ***environp = _NSGetEnviron();
17 static char **alloced; /* if allocated space before */
18 char *c;
19 int l_value, offset;
20 @@ -73,30 +74,30 @@
21 int cnt;
22 char **p;
23
24 - for (p = environ, cnt = 0; *p; ++p, ++cnt);
25 - if (alloced == environ) { /* just increase size */
26 - p = (char **)realloc((char *)environ,
27 + for (p = *environp, cnt = 0; *p; ++p, ++cnt);
28 + if (alloced == *environp) { /* just increase size */
29 + p = (char **)realloc((char *)*environp,
30 (size_t)(sizeof(char *) * (cnt + 2)));
31 if (!p)
32 return (-1);
33 - alloced = environ = p;
34 + alloced = *environp = p;
35 }
36 else { /* get new space */
37 /* copy old entries into it */
38 p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
39 if (!p)
40 return (-1);
41 - bcopy(environ, p, cnt * sizeof(char *));
42 - alloced = environ = p;
43 + bcopy(*environp, p, cnt * sizeof(char *));
44 + alloced = *environp = p;
45 }
46 - environ[cnt + 1] = NULL;
47 + (*environp)[cnt + 1] = NULL;
48 offset = cnt;
49 }
50 for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */
51 - if (!(environ[offset] = /* name + `=' + value */
52 + if (!((*environp)[offset] = /* name + `=' + value */
53 malloc((size_t)((int)(c - name) + l_value + 2))))
54 return (-1);
55 - for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
56 + for (c = (*environp)[offset]; (*c = *name++) && *c != '='; ++c);
57 for (*c++ = '='; (*c++ = *value++); );
58 return (0);
59 }
60 @@ -109,7 +110,7 @@
61 unsetenv(name)
62 const char *name;
63 {
64 - extern char **environ;
65 + char **environ = *_NSGetEnviron();
66 char **p;
67 int offset;
68