sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libast / common / misc / getenv.c
blob9252938d0033ff92de4e3791d9c6bf125882c996
1 /***********************************************************************
2 * *
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 *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 #if _UWIN && __STDPP__
25 __STDPP__directive pragma pp:hide getenv
26 #endif
28 #include "intercepts.h"
30 #if _UWIN && __STDPP__
31 __STDPP__directive pragma pp:nohide getenv
32 #endif
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
42 #if _BLD_3d
44 #else
45 = { 0 };
46 #endif
48 #if _UWIN && !defined(getenv)
50 #include <windows.h>
52 extern char** environ;
54 static char*
55 default_getenv(const char* name)
57 register char** av;
58 register const char* cp;
59 register const char* sp;
60 register char c0;
61 register char c1;
63 av = environ;
64 if (!av || !name || !(c0 = *name))
65 return 0;
66 if (!(c1 = *++name))
67 c1 = '=';
68 while (cp = *av++)
70 if (cp[0] != c0 || cp[1] != c1)
71 continue;
72 sp = name;
73 cp++;
74 while (*sp && *sp++ == *cp++);
75 if (*(sp-1) != *(cp-1))
76 continue;
77 if (*sp == 0 && *cp == '=')
78 return (char*)(cp+1);
80 return 0;
83 #endif
86 * get name from the environment
89 #if defined(__EXPORT__) && defined(getenv)
90 #define extern __EXPORT__
91 #endif
93 extern char*
94 getenv(const char* name)
96 #if _UWIN && !defined(getenv) /* for ast54 compatibility */
97 HANDLE dll;
99 static char* (*posix_getenv)(const char*);
101 if (!posix_getenv)
103 if (dll = GetModuleHandle("posix.dll"))
104 posix_getenv = (char*(*)(const char*))GetProcAddress(dll, "getenv");
105 if (!posix_getenv)
106 posix_getenv = default_getenv;
108 return intercepts.intercept_getenv ? (*intercepts.intercept_getenv)(name) : (*posix_getenv)(name);
109 #else
110 #undef getenv
111 return intercepts.intercept_getenv ? (*intercepts.intercept_getenv)(name) : getenv(name);
112 #endif