ReactOS 0.4.16-dev-401-g45b008d
dllmain.c
Go to the documentation of this file.
1/*
2 * dllmain.c
3 *
4 * ReactOS CRTDLL.DLL Compatibility Library
5 *
6 * THIS SOFTWARE IS NOT COPYRIGHTED
7 *
8 * This source code is offered for use in the public domain. You may
9 * use, modify or distribute it freely.
10 *
11 * This code is distributed in the hope that it will be useful but
12 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
13 * DISCLAMED. This includes but is not limited to warranties of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 */
17
18#include "precomp.h"
19#include <mbctype.h>
20#include <sys/stat.h>
22
23#include <wine/debug.h>
25
26/* from msvcrt */
27extern void __getmainargs( int *argc, char ***argv, char ***envp,
28 int expand_wildcards, int *new_mode );
29
30/* EXTERNAL PROTOTYPES ********************************************************/
31
33
34extern void FreeEnvironment(char **environment);
35
36
37unsigned int CRTDLL__basemajor_dll = 0;
38unsigned int CRTDLL__baseminor_dll = 0;
39unsigned int CRTDLL__baseversion_dll = 0;
40unsigned int CRTDLL__cpumode_dll = 0;
41unsigned int CRTDLL__osmajor_dll = 0;
42unsigned int CRTDLL__osminor_dll = 0;
43unsigned int CRTDLL__osmode_dll = 0;
44unsigned int CRTDLL__osversion_dll = 0;
46
47#undef _environ
48extern char** _environ; /* pointer to environment block */
49extern char** __initenv; /* pointer to initial environment block */
50extern wchar_t** _wenviron; /* pointer to environment block */
51extern wchar_t** __winitenv; /* pointer to initial environment block */
52
53/* dev_t is a short in crtdll but an unsigned int in msvcrt */
54typedef short crtdll_dev_t;
55
57{
60 unsigned short st_mode;
61 short st_nlink;
62 short st_uid;
63 short st_gid;
69};
70
71/* convert struct _stat from crtdll format to msvcrt format */
72static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
73{
74 dst->st_dev = src->st_dev;
75 dst->st_ino = src->st_ino;
76 dst->st_mode = src->st_mode;
77 dst->st_nlink = src->st_nlink;
78 dst->st_uid = src->st_uid;
79 dst->st_gid = src->st_gid;
80 dst->st_rdev = src->st_rdev;
81 dst->st_size = src->st_size;
82 dst->st_atime = src->st_atime;
83 dst->st_mtime = src->st_mtime;
84 dst->st_ctime = src->st_ctime;
85}
86
87/* LIBRARY ENTRY POINT ********************************************************/
88
89BOOL
92{
94 switch (dwReason)
95 {
98
99 /* initialize version info */
100 CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
101 CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
103 CRTDLL__cpumode_dll = 1; /* FIXME */
104 CRTDLL__osmajor_dll = (version >>8) & 0xFF;
105 CRTDLL__osminor_dll = (version & 0xFF);
106 CRTDLL__osmode_dll = 1; /* FIXME */
107 CRTDLL__osversion_dll = (version & 0xFFFF);
108
109 if (!crt_process_init())
110 {
111 ERR("crt_init() failed!\n");
112 return FALSE;
113 }
114
115 TRACE("Attach done\n");
116 break;
118 break;
119
122 break;
123
125 TRACE("Detach\n");
126 /* Deinit of the WINE code */
128 if (reserved) break;
131 //msvcrt_free_console();
132 //msvcrt_free_args();
133 //msvcrt_free_signals();
135 if (!msvcrt_free_tls())
136 return FALSE;
137 //MSVCRT__free_locale(MSVCRT_locale);
138
141 if (_wenviron)
142 FreeEnvironment((char**)_wenviron);
143
144 if (__initenv && __initenv != _environ)
146 if (_environ)
148
149 TRACE("Detach done\n");
150 break;
151 }
152
153 return TRUE;
154}
155
156
157/*********************************************************************
158 * __GetMainArgs (CRTDLL.@)
159 */
160void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
161{
162 int new_mode = 0;
163 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
164}
165
166
167/*********************************************************************
168 * _fstat (CRTDLL.@)
169 */
171{
172 extern int _fstat(int,struct _stat*);
173 struct _stat st;
174 int ret;
175
176 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
177 return ret;
178}
179
180
181/*********************************************************************
182 * _stat (CRTDLL.@)
183 */
184int CRTDLL__stat(const char* path, struct crtdll_stat * buf)
185{
186 extern int _stat(const char*,struct _stat*);
187 struct _stat st;
188 int ret;
189
190 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
191 return ret;
192}
193
194
195/*********************************************************************
196 * _strdec (CRTDLL.@)
197 */
198char *_strdec(const char *str1, const char *str2)
199{
200 return (char *)(str2 - 1);
201}
202
203
204/*********************************************************************
205 * _strinc (CRTDLL.@)
206 */
207char *_strinc(const char *str)
208{
209 return (char *)(str + 1);
210}
211
212
213/*********************************************************************
214 * _strncnt (CRTDLL.@)
215 */
216size_t _strncnt(const char *str, size_t maxlen)
217{
218 size_t len = strlen(str);
219 return (len > maxlen) ? maxlen : len;
220}
221
222
223/*********************************************************************
224 * _strnextc (CRTDLL.@)
225 */
226unsigned int _strnextc(const char *str)
227{
228 return (unsigned int)str[0];
229}
230
231
232/*********************************************************************
233 * _strninc (CRTDLL.@)
234 */
235char *_strninc(const char *str, size_t len)
236{
237 return (char *)(str + len);
238}
239
240
241/*********************************************************************
242 * _strspnp (CRTDLL.@)
243 */
244char *_strspnp( const char *str1, const char *str2)
245{
246 str1 += strspn( str1, str2 );
247 return *str1 ? (char*)str1 : NULL;
248}
249
250/* EOF */
static int argc
Definition: ServiceArgs.c:12
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ERR(fmt,...)
Definition: precomp.h:57
DWORD dwReason
Definition: misc.cpp:141
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition: dllmain.c:52
unsigned int CRTDLL__osminor_dll
Definition: dllmain.c:42
unsigned int CRTDLL__cpumode_dll
Definition: dllmain.c:40
void FreeEnvironment(char **environment)
Definition: environ.c:190
static void convert_struct_stat(struct crtdll_stat *dst, const struct _stat *src)
Definition: dllmain.c:72
char ** __initenv
Definition: environ.c:24
unsigned int CRTDLL__baseminor_dll
Definition: dllmain.c:38
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** _wenviron
Definition: environ.c:23
void __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: getargs.c:182
void __GetMainArgs(int *argc, char ***argv, char ***envp, int expand_wildcards)
Definition: dllmain.c:160
unsigned int CRTDLL__osversion_dll
Definition: dllmain.c:44
unsigned int CRTDLL__basemajor_dll
Definition: dllmain.c:37
BOOL crt_process_init(void)
Definition: crt_init.c:21
unsigned int CRTDLL__baseversion_dll
Definition: dllmain.c:39
unsigned int CRTDLL__osmajor_dll
Definition: dllmain.c:41
unsigned int CRTDLL__osmode_dll
Definition: dllmain.c:43
short crtdll_dev_t
Definition: dllmain.c:54
char ** _environ
Definition: environ.c:22
int _fileinfo_dll
Definition: dllmain.c:45
int CRTDLL__stat(const char *path, struct crtdll_stat *buf)
Definition: dllmain.c:184
int CRTDLL__fstat(int fd, struct crtdll_stat *buf)
Definition: dllmain.c:170
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
static const WCHAR version[]
Definition: asmname.c:66
r reserved
Definition: btrfs.c:3006
__kernel_time_t time_t
Definition: linux.h:252
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
long _off_t
Definition: stdio.h:73
_CRTIMP int __cdecl _fstat(_In_ int _FileDes, _Out_ struct _stat *_Stat)
#define _strnextc(_cpc)
Definition: tchar.h:1518
#define _strninc(_pc, _sz)
Definition: tchar.h:1519
#define _strdec(_cpc1, _cpc2)
Definition: tchar.h:1516
#define _strinc(_pc)
Definition: tchar.h:1517
#define _strncnt(_cpc, _sz)
Definition: tchar.h:1521
#define _strspnp(_cpc1, _cpc2)
Definition: tchar.h:1522
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
void msvcrt_free_io(void)
Definition: file.c:1100
#define argv
Definition: mplay32.c:18
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
const WCHAR * str
_Check_return_ _CRTIMP size_t __cdecl strspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
unsigned short _ino_t
Definition: types.h:17
void msvcrt_free_tls_mem(void)
Definition: tls.c:51
BOOL msvcrt_free_tls(void)
Definition: tls.c:21
void msvcrt_free_popen_data(void)
Definition: popen.c:29
static int fd
Definition: io.c:51
#define TRACE(s)
Definition: solgame.cpp:4
Definition: stat.h:40
short st_nlink
Definition: dllmain.c:61
short st_gid
Definition: dllmain.c:63
unsigned short st_mode
Definition: dllmain.c:60
time_t st_ctime
Definition: dllmain.c:68
_ino_t st_ino
Definition: dllmain.c:59
time_t st_mtime
Definition: dllmain.c:67
time_t st_atime
Definition: dllmain.c:66
short st_uid
Definition: dllmain.c:62
_off_t st_size
Definition: dllmain.c:65
crtdll_dev_t st_dev
Definition: dllmain.c:58
crtdll_dev_t st_rdev
Definition: dllmain.c:64
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define WINAPI
Definition: msvc.h:6