xref: /onnv-gate/usr/src/lib/libast/common/port/astdynamic.c (revision 4887:feebf9260c2e)
1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
18*4887Schin *                  David Korn <dgk@research.att.com>                   *
19*4887Schin *                   Phong Vo <kpv@research.att.com>                    *
20*4887Schin *                                                                      *
21*4887Schin ***********************************************************************/
22*4887Schin #pragma prototyped
23*4887Schin 
24*4887Schin /*
25*4887Schin  * ast dynamic data initialization
26*4887Schin  */
27*4887Schin 
28*4887Schin #ifdef _UWIN
29*4887Schin 
30*4887Schin #define _std_def_cfree	1
31*4887Schin 
32*4887Schin #include <sfio_t.h>
33*4887Schin #include <ast.h>
34*4887Schin 
35*4887Schin #undef	strcoll
36*4887Schin 
37*4887Schin #include <ast_windows.h>
38*4887Schin 
39*4887Schin extern Sfio_t	_Sfstdin;
40*4887Schin extern Sfio_t	_Sfstdout;
41*4887Schin extern Sfio_t	_Sfstderr;
42*4887Schin 
43*4887Schin #include "sfhdr.h"
44*4887Schin 
45*4887Schin #undef	sfstdin
46*4887Schin #undef	sfstdout
47*4887Schin #undef	sfstderr
48*4887Schin 
49*4887Schin #if defined(__EXPORT__)
50*4887Schin #define extern		__EXPORT__
51*4887Schin #endif
52*4887Schin 
53*4887Schin /*
54*4887Schin  * for backward compatibility with early UNIX
55*4887Schin  */
56*4887Schin 
57*4887Schin extern void
58*4887Schin cfree(void* addr)
59*4887Schin {
60*4887Schin 	free(addr);
61*4887Schin }
62*4887Schin 
63*4887Schin extern void
64*4887Schin _ast_libinit(void* in, void* out, void* err)
65*4887Schin {
66*4887Schin 	Sfio_t*		sp;
67*4887Schin 
68*4887Schin 	sp = (Sfio_t*)in;
69*4887Schin 	*sp =  _Sfstdin;
70*4887Schin 	sfstdin = sp;
71*4887Schin 	sp = (Sfio_t*)out;
72*4887Schin 	*sp =  _Sfstdout;
73*4887Schin 	sfstdout = sp;
74*4887Schin 	sp = (Sfio_t*)err;
75*4887Schin 	*sp =  _Sfstderr;
76*4887Schin 	sfstderr = sp;
77*4887Schin }
78*4887Schin 
79*4887Schin extern void
80*4887Schin _ast_init(void)
81*4887Schin {
82*4887Schin 	struct _astdll*	ap = _ast_getdll();
83*4887Schin 
84*4887Schin 	_ast_libinit(ap->_ast_stdin,ap->_ast_stdout,ap->_ast_stderr);
85*4887Schin }
86*4887Schin 
87*4887Schin extern void
88*4887Schin _ast_exit(void)
89*4887Schin {
90*4887Schin 	if (_Sfcleanup)
91*4887Schin 		(*_Sfcleanup)();
92*4887Schin }
93*4887Schin 
94*4887Schin BOOL WINAPI
95*4887Schin DllMain(HINSTANCE hinst, DWORD reason, VOID* reserved)
96*4887Schin {
97*4887Schin 	switch (reason)
98*4887Schin 	{
99*4887Schin 	case DLL_PROCESS_ATTACH:
100*4887Schin 		break;
101*4887Schin 	case DLL_PROCESS_DETACH:
102*4887Schin 		_ast_exit();
103*4887Schin 		break;
104*4887Schin 	}
105*4887Schin 	return 1;
106*4887Schin }
107*4887Schin 
108*4887Schin #else
109*4887Schin 
110*4887Schin #include <ast.h>
111*4887Schin 
112*4887Schin #if _dll_data_intercept && ( _DLL_BLD || _BLD_DLL )
113*4887Schin 
114*4887Schin #undef	environ
115*4887Schin 
116*4887Schin extern char**	environ;
117*4887Schin 
118*4887Schin struct _astdll	_ast_dll = { &environ };
119*4887Schin 
120*4887Schin struct _astdll*
121*4887Schin _ast_getdll(void)
122*4887Schin {
123*4887Schin 	return &_ast_dll;
124*4887Schin }
125*4887Schin 
126*4887Schin #else
127*4887Schin 
128*4887Schin NoN(astdynamic)
129*4887Schin 
130*4887Schin #endif
131*4887Schin 
132*4887Schin #endif
133