10 /* Initialized to zero, meaning "not malloc'd" */
11 static size_t __environ_size;
13 /* str should be a duplicated version of the input string;
14 len is the length of the key including the = sign */
15 static int _putenv(char *str, size_t len, int overwrite)
21 n = 1; /* Include space for final NULL */
22 for ( p = environ ; (q = *p) ; p++ ) {
24 if ( !strncmp(q,str,len) ) {
28 *p = str; /* Memory leak... */
33 /* Need to extend the environment */
34 if ( n < __environ_size ) {
39 if ( __environ_size ) {
40 newenv = realloc(environ, (__environ_size << 1)*sizeof(char *));
46 /* Make a reasonable guess how much more space we need */
47 size_t newsize = n+32;
48 newenv = malloc(newsize*sizeof(char *));
52 memcpy(newenv, environ, n*sizeof(char *));
53 __environ_size = newsize;
62 int putenv(const char *str)
74 for ( z = str ; *z ; z++ ) {
89 return _putenv(s, len, 1);
92 int setenv(const char *name, const char *val, int overwrite)
98 if ( !name || !name[0] ) {
104 for ( z = name ; *z ; z++ ) {
120 memcpy(s+l1+1, val, l2);
123 return _putenv(s, l1+1, overwrite);