xref: /titanic_41/usr/src/lib/libast/common/port/astdynamic.c (revision 66ea84940ca8687745ad2a165ef9bf49ec13996f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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
23 
24 /*
25  * ast dynamic data initialization
26  */
27 
28 #ifdef _UWIN
29 
30 #define _std_def_cfree	1
31 
32 #include <sfio_t.h>
33 #include <ast.h>
34 
35 #undef	strcoll
36 
37 #include <ast_windows.h>
38 
39 extern Sfio_t	_Sfstdin;
40 extern Sfio_t	_Sfstdout;
41 extern Sfio_t	_Sfstderr;
42 
43 #include "sfhdr.h"
44 
45 #undef	sfstdin
46 #undef	sfstdout
47 #undef	sfstderr
48 
49 #if defined(__EXPORT__)
50 #define extern		__EXPORT__
51 #endif
52 
53 /*
54  * for backward compatibility with early UNIX
55  */
56 
57 extern void
58 cfree(void* addr)
59 {
60 	free(addr);
61 }
62 
63 extern void
64 _ast_libinit(void* in, void* out, void* err)
65 {
66 	Sfio_t*		sp;
67 
68 	sp = (Sfio_t*)in;
69 	*sp =  _Sfstdin;
70 	sfstdin = sp;
71 	sp = (Sfio_t*)out;
72 	*sp =  _Sfstdout;
73 	sfstdout = sp;
74 	sp = (Sfio_t*)err;
75 	*sp =  _Sfstderr;
76 	sfstderr = sp;
77 }
78 
79 extern void
80 _ast_init(void)
81 {
82 	struct _astdll*	ap = _ast_getdll();
83 
84 	_ast_libinit(ap->_ast_stdin,ap->_ast_stdout,ap->_ast_stderr);
85 }
86 
87 extern void
88 _ast_exit(void)
89 {
90 	if (_Sfcleanup)
91 		(*_Sfcleanup)();
92 }
93 
94 BOOL WINAPI
95 DllMain(HINSTANCE hinst, DWORD reason, VOID* reserved)
96 {
97 	switch (reason)
98 	{
99 	case DLL_PROCESS_ATTACH:
100 		break;
101 	case DLL_PROCESS_DETACH:
102 		_ast_exit();
103 		break;
104 	}
105 	return 1;
106 }
107 
108 #else
109 
110 #include <ast.h>
111 
112 #if _dll_data_intercept && ( _DLL_BLD || _BLD_DLL )
113 
114 #undef	environ
115 
116 extern char**	environ;
117 
118 struct _astdll	_ast_dll = { &environ };
119 
120 struct _astdll*
121 _ast_getdll(void)
122 {
123 	return &_ast_dll;
124 }
125 
126 #else
127 
128 NoN(astdynamic)
129 
130 #endif
131 
132 #endif
133