1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 #include "intercepts.h"
29 * put name=value in the environment
30 * pointer to value returned
33 * setenviron("N=V") add N=V
34 * setenviron("N") delete N
35 * setenviron(0) expect more (pre-fork optimization)
37 * _ always placed at the top
40 #define INCREMENT 16 /* environ increment */
43 setenviron(const char* akey
)
46 static char** envv
; /* recorded environ */
47 static char** next
; /* next free slot */
48 static char** last
; /* last free slot (0) */
49 static char ok
[] = ""; /* delete/optimization ok return*/
51 char* key
= (char*)akey
;
52 register char** v
= environ
;
53 register char** p
= envv
;
59 if (intercepts
.intercept_setenviron
)
60 return (*intercepts
.intercept_setenviron
)(akey
);
66 else if (p
!= v
|| !v
)
71 n
= v
- environ
+ INCREMENT
;
76 if (!p
|| (last
- p
+ 1) < n
)
78 if (!p
&& fs3d(FS3D_TEST
))
81 * kick 3d initialization
84 close(open(".", O_RDONLY
));
87 if (!(p
= newof(p
, char*, n
, 0)))
92 if (v
&& v
[0] && v
[0][0] == '_' && v
[0][1] == '=')
100 if (p
[0][0] == '_' && p
[0][1] == '=')
107 else if (next
== last
)
109 n
= last
- v
+ INCREMENT
+ 1;
110 if (!(p
= newof(p
, char*, n
, 0)))
113 next
= last
- INCREMENT
;
123 if (!*t
|| *t
== '=')
135 return (s
= strchr(key
, '=')) ? s
+ 1 : (char*)0;
139 } while (*t
++ == *s
++);
141 if (!(s
= strchr(key
, '=')))