1 --- putenv.c.orig 2011-04-12 22:08:20.000000000 -0700
2 +++ putenv.c 2011-04-13 14:33:50.000000000 -0700
3 @@ -35,22 +35,81 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/
7 +#include <sys/types.h>
9 +#include <crt_externs.h>
10 +#include <malloc/malloc.h>
13 +extern malloc_zone_t *__zone0;
14 +#ifdef LEGACY_CRT1_ENVIRON
15 +extern char **_saved_environ;
16 +#endif /* LEGACY_CRT1_ENVIRON */
18 +extern void __malloc_check_env_name(const char *);
19 +__private_extern__ int __setenv(const char *, const char *, int, int, char ***, malloc_zone_t *);
21 +#ifndef BUILDING_VARIANT
23 + * _putenvp -- SPI using an arbitrary pointer to string array (the array must
24 + * have been created with malloc) and an env state, created by _allocenvstate().
25 + * Returns ptr to value associated with name, if any, else NULL.
28 +_putenvp(char *str, char ***envp, void *state)
30 + /* insure __zone0 is set up */
32 + __zone0 = malloc_create_zone(0, 0);
38 + return (__setenv(str, NULL, 1, 0, envp, (state ? (malloc_zone_t *)state : __zone0)));
40 +#endif /* BUILDING_VARIANT */
49 +#ifdef LEGACY_CRT1_ENVIRON
51 +#endif /* LEGACY_CRT1_ENVIRON */
53 - if ((p = strdup(str)) == NULL)
55 + if (str == NULL || *str == 0 || index(str, '=') == NULL) {
58 - if ((equal = index(p, '=')) == NULL) {
61 +#else /* !__DARWIN_UNIX03 */
62 + if (index(str, '=') == NULL)
64 +#endif /* __DARWIN_UNIX03 */
65 + /* insure __zone0 is set up before calling __malloc_check_env_name */
67 + __zone0 = malloc_create_zone(0, 0);
74 - rval = setenv(p, equal + 1, 1);
77 + __malloc_check_env_name(str); /* see if we are changing a malloc environment variable */
78 +#ifdef LEGACY_CRT1_ENVIRON
80 +#else /* !LEGACY_CRT1_ENVIRON */
82 +#endif /* !LEGACY_CRT1_ENVIRON */
83 + __setenv(str, NULL, 1,
86 +#else /* !__DARWIN_UNIX03 */
88 +#endif /* __DARWIN_UNIX03 */
89 + _NSGetEnviron(), __zone0);
90 +#ifdef LEGACY_CRT1_ENVIRON
91 + _saved_environ = *_NSGetEnviron();
93 +#endif /* LEGACY_CRT1_ENVIRON */