1 /* $Id: dllmain.c 12852 2005-01-06 13:58:04Z mf $
5 * ReactOS MSVCRT.DLL Compatibility Library
7 * THIS SOFTWARE IS NOT COPYRIGHTED
9 * This source code is offered for use in the public domain. You may
10 * use, modify or distribute it freely.
12 * This code is distributed in the hope that it will be useful but
13 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
14 * DISCLAMED. This includes but is not limited to warrenties of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * $Date: 2005-01-06 14:58:04 +0100 (Thu, 06 Jan 2005) $
24 #include <internal/wine/msvcrt.h>
28 #include <internal/debug.h>
31 /* EXTERNAL PROTOTYPES ********************************************************/
33 //void __fileno_init(void);
34 extern BOOL
__fileno_init(void);
35 extern int BlockEnvToEnvironA(void);
36 extern int BlockEnvToEnvironW(void);
37 extern void FreeEnvironment(char **environment
);
38 extern void _atexit_cleanup(void);
40 extern unsigned int _osver
;
41 extern unsigned int _winminor
;
42 extern unsigned int _winmajor
;
43 extern unsigned int _winver
;
45 unsigned int CRTDLL__basemajor_dll
;
46 unsigned int CRTDLL__baseminor_dll
;
47 unsigned int CRTDLL__baseversion_dll
;
48 unsigned int CRTDLL__cpumode_dll
;
49 unsigned int CRTDLL__osmajor_dll
;
50 unsigned int CRTDLL__osminor_dll
;
51 unsigned int CRTDLL__osmode_dll
;
52 unsigned int CRTDLL__osversion_dll
;
54 extern char* _acmdln
; /* pointer to ascii command line */
55 extern wchar_t* _wcmdln
; /* pointer to wide character command line */
57 extern char** _environ
; /* pointer to environment block */
58 extern char** __initenv
; /* pointer to initial environment block */
59 extern wchar_t** _wenviron
; /* pointer to environment block */
60 extern wchar_t** __winitenv
; /* pointer to initial environment block */
64 /* dev_t is a short in crtdll but an unsigned int in msvcrt */
65 typedef short crtdll_dev_t
;
71 unsigned short st_mode
;
82 /* convert struct _stat from crtdll format to msvcrt format */
83 static void convert_struct_stat( struct crtdll_stat
*dst
, const struct _stat
*src
)
85 dst
->st_dev
= src
->st_dev
;
86 dst
->st_ino
= src
->st_ino
;
87 dst
->st_mode
= src
->st_mode
;
88 dst
->st_nlink
= src
->st_nlink
;
89 dst
->st_uid
= src
->st_uid
;
90 dst
->st_gid
= src
->st_gid
;
91 dst
->st_rdev
= src
->st_rdev
;
92 dst
->st_size
= src
->st_size
;
93 dst
->st_atime
= src
->st_atime
;
94 dst
->st_mtime
= src
->st_mtime
;
95 dst
->st_ctime
= src
->st_ctime
;
99 extern void __getmainargs( int *argc
, char ***argv
, char ***envp
,
100 int expand_wildcards
, int *new_mode
);
102 /* LIBRARY GLOBAL VARIABLES ***************************************************/
104 HANDLE hHeap
= NULL
; /* handle for heap */
107 /* LIBRARY ENTRY POINT ********************************************************/
111 DllMain(PVOID hinstDll
, ULONG dwReason
, PVOID reserved
)
115 case DLL_PROCESS_ATTACH
://1
116 /* initialize version info */
117 DPRINT("Attach %d\n", nAttachCount
);
119 _osver
= GetVersion();
121 CRTDLL__basemajor_dll
= (_osver
>> 24) & 0xFF;
122 CRTDLL__baseminor_dll
= (_osver
>> 16) & 0xFF;
123 CRTDLL__baseversion_dll
= (_osver
>> 16);
124 CRTDLL__cpumode_dll
= 1; /* FIXME */
125 CRTDLL__osmajor_dll
= (_osver
>>8) & 0xFF;
126 CRTDLL__osminor_dll
= (_osver
& 0xFF);
127 CRTDLL__osmode_dll
= 1; /* FIXME */
128 CRTDLL__osversion_dll
= (_osver
& 0xFFFF);
130 _winmajor
= (_osver
>> 8) & 0xFF;
131 _winminor
= _osver
& 0xFF;
132 _winver
= (_winmajor
<< 8) + _winminor
;
133 _osver
= (_osver
>> 16) & 0xFFFF;
134 hHeap
= HeapCreate(0, 100000, 0);
137 if (!__fileno_init())
140 /* create tls stuff */
141 if (!CreateThreadData())
144 if (BlockEnvToEnvironA() < 0)
147 if (BlockEnvToEnvironW() < 0)
149 FreeEnvironment((char**)_wenviron
);
153 _acmdln
= _strdup(GetCommandLineA());
154 _wcmdln
= _wcsdup(GetCommandLineW());
156 /* FIXME: more initializations... */
158 /* FIXME: Initialization of the WINE code */
159 msvcrt_init_mt_locks();
161 DPRINT("Attach done\n");
164 case DLL_THREAD_ATTACH
://2
167 case DLL_THREAD_DETACH
://4
168 FreeThreadData(NULL
);
171 case DLL_PROCESS_DETACH
://0
172 DPRINT("Detach %d\n", nAttachCount
);
173 /* FIXME: more cleanup... */
177 /* destroy tls stuff */
180 if (__winitenv
&& __winitenv
!= _wenviron
)
181 FreeEnvironment((char**)__winitenv
);
183 FreeEnvironment((char**)_wenviron
);
185 if (__initenv
&& __initenv
!= _environ
)
186 FreeEnvironment(__initenv
);
188 FreeEnvironment(_environ
);
193 DPRINT("Detach done\n");
203 /*********************************************************************
204 * __GetMainArgs (CRTDLL.@)
206 void __GetMainArgs( int *argc
, char ***argv
, char ***envp
, int expand_wildcards
)
209 __getmainargs( argc
, argv
, envp
, expand_wildcards
, &new_mode
);
213 /*********************************************************************
216 int CRTDLL__fstat(int fd
, struct crtdll_stat
* buf
)
218 extern int _fstat(int,struct _stat
*);
222 if (!(ret
= _fstat( fd
, &st
))) convert_struct_stat( buf
, &st
);
227 /*********************************************************************
230 int CRTDLL__stat(const char* path
, struct crtdll_stat
* buf
)
232 extern int _stat(const char*,struct _stat
*);
236 if (!(ret
= _stat( path
, &st
))) convert_struct_stat( buf
, &st
);
241 /*********************************************************************
244 char *_strdec(const char *str1
, const char *str2
)
246 return (char *)(str2
- 1);
250 /*********************************************************************
253 char *_strinc(const char *str
)
255 return (char *)(str
+ 1);
259 /*********************************************************************
260 * _strncnt (CRTDLL.@)
262 size_t _strncnt(const char *str
, size_t maxlen
)
264 size_t len
= strlen(str
);
265 return (len
> maxlen
) ? maxlen
: len
;
269 /*********************************************************************
270 * _strnextc (CRTDLL.@)
272 unsigned int _strnextc(const char *str
)
274 return (unsigned int)str
[0];
278 /*********************************************************************
279 * _strninc (CRTDLL.@)
281 char *_strninc(const char *str
, size_t len
)
283 return (char *)(str
+ len
);
287 /*********************************************************************
288 * _strspnp (CRTDLL.@)
290 char *_strspnp( const char *str1
, const char *str2
)
292 str1
+= strspn( str1
, str2
);
293 return *str1
? (char*)str1
: NULL
;