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 #if _UWIN && __STDPP__
25 __STDPP__directive pragma pp
:hide getenv
28 #include "intercepts.h"
30 #if _UWIN && __STDPP__
31 __STDPP__directive pragma pp
:nohide getenv
35 * NOTE: the "intercepts" definition is here instead of astintercept.c because some
36 * static linkers miss lone references to "intercepts" without "astintercept()"
37 * ALSO: { 0 } definition required by some dynamic linkers averse to common symbols
38 * UWIN: no _ast_getenv macro map to maintain ast54 compatibility
41 Intercepts_t intercepts
48 #if _UWIN && !defined(getenv)
52 extern char** environ
;
55 default_getenv(const char* name
)
58 register const char* cp
;
59 register const char* sp
;
64 if (!av
|| !name
|| !(c0
= *name
))
70 if (cp
[0] != c0
|| cp
[1] != c1
)
74 while (*sp
&& *sp
++ == *cp
++);
75 if (*(sp
-1) != *(cp
-1))
77 if (*sp
== 0 && *cp
== '=')
86 * get name from the environment
89 #if defined(__EXPORT__) && defined(getenv)
90 #define extern __EXPORT__
94 getenv(const char* name
)
96 #if _UWIN && !defined(getenv) /* for ast54 compatibility */
99 static char* (*posix_getenv
)(const char*);
103 if (dll
= GetModuleHandle("posix.dll"))
104 posix_getenv
= (char*(*)(const char*))GetProcAddress(dll
, "getenv");
106 posix_getenv
= default_getenv
;
108 return intercepts
.intercept_getenv
? (*intercepts
.intercept_getenv
)(name
) : (*posix_getenv
)(name
);
111 return intercepts
.intercept_getenv
? (*intercepts
.intercept_getenv
)(name
) : getenv(name
);