ReactOS 0.4.16-dev-2332-g4cba65d
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 <sys/stat.h>
19#include <assert.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <mbstring.h>
23#include <windef.h>
24
25/* from msvcrt */
26extern void __getmainargs( int *argc, char ***argv, char ***envp,
27 int expand_wildcards, int *new_mode );
28
29/* EXTERNAL PROTOTYPES ********************************************************/
30
31unsigned int CRTDLL__basemajor_dll = 0;
32unsigned int CRTDLL__baseminor_dll = 0;
33unsigned int CRTDLL__baseversion_dll = 0;
34unsigned int CRTDLL__cpumode_dll = 0;
35unsigned int CRTDLL__osmajor_dll = 0;
36unsigned int CRTDLL__osminor_dll = 0;
37unsigned int CRTDLL__osmode_dll = 0;
38unsigned int CRTDLL__osversion_dll = 0;
40
41#undef _environ
42extern char** _environ; /* pointer to environment block */
43extern char** __initenv; /* pointer to initial environment block */
44extern wchar_t** _wenviron; /* pointer to environment block */
45extern wchar_t** __winitenv; /* pointer to initial environment block */
46
47/* dev_t is a short in crtdll but an unsigned int in msvcrt */
48typedef short crtdll_dev_t;
49
51{
54 unsigned short st_mode;
55 short st_nlink;
56 short st_uid;
57 short st_gid;
63};
64
65/* convert struct _stat from crtdll format to msvcrt format */
66static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
67{
68 dst->st_dev = src->st_dev;
69 dst->st_ino = src->st_ino;
70 dst->st_mode = src->st_mode;
71 dst->st_nlink = src->st_nlink;
72 dst->st_uid = src->st_uid;
73 dst->st_gid = src->st_gid;
74 dst->st_rdev = src->st_rdev;
75 dst->st_size = src->st_size;
76 dst->st_atime = src->st_atime;
77 dst->st_mtime = src->st_mtime;
78 dst->st_ctime = src->st_ctime;
79}
80
81
82/*********************************************************************
83 * __GetMainArgs (CRTDLL.@)
84 */
85void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
86{
87 int new_mode = 0;
88 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
89}
90
91
92/*********************************************************************
93 * _fstat (CRTDLL.@)
94 */
96{
97 extern int _fstat(int,struct _stat*);
98 struct _stat st;
99 int ret;
100
101 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
102 return ret;
103}
104
105
106/*********************************************************************
107 * _stat (CRTDLL.@)
108 */
109int CRTDLL__stat(const char* path, struct crtdll_stat * buf)
110{
111 extern int _stat(const char*,struct _stat*);
112 struct _stat st;
113 int ret;
114
115 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
116 return ret;
117}
118
119
120/*********************************************************************
121 * _strdec (CRTDLL.@)
122 */
123char *_strdec(const char *str1, const char *str2)
124{
125 return (char *)(str2 - 1);
126}
127
128
129/*********************************************************************
130 * _strinc (CRTDLL.@)
131 */
132char *_strinc(const char *str)
133{
134 return (char *)(str + 1);
135}
136
137
138/*********************************************************************
139 * _strncnt (CRTDLL.@)
140 */
141size_t _strncnt(const char *str, size_t maxlen)
142{
143 size_t len = strlen(str);
144 return (len > maxlen) ? maxlen : len;
145}
146
147
148/*********************************************************************
149 * _strnextc (CRTDLL.@)
150 */
151unsigned int _strnextc(const char *str)
152{
153 return (unsigned int)str[0];
154}
155
156
157/*********************************************************************
158 * _strninc (CRTDLL.@)
159 */
160char *_strninc(const char *str, size_t len)
161{
162 return (char *)(str + len);
163}
164
165
166/*********************************************************************
167 * _strspnp (CRTDLL.@)
168 */
169char *_strspnp( const char *str1, const char *str2)
170{
171 str1 += strspn( str1, str2 );
172 return *str1 ? (char*)str1 : NULL;
173}
174
175/*********************************************************************
176 * _mbsstr (CRTDLL.@)
177 */
178unsigned char* CRTDLL__mbsstr(const unsigned char* Str, const unsigned char* Substr)
179{
180 if (!*Str && !*Substr)
181 return NULL;
182 return (unsigned char*)strstr((const char*)Str, (const char*)Substr);
183}
184
185/*********************************************************************
186 * sprintf (CRTDLL.@)
187 */
188int CRTDLL_sprintf(char* buffer, const char* format, ...)
189{
191 int ret;
192
193 /* Access both buffers to emulate CRTDLL exception behavior */
194 (void)*(volatile char*)buffer;
195 (void)*(volatile char*)format;
196
199 va_end(args);
200 return ret;
201}
202
203/*********************************************************************
204 * strtoul (CRTDLL.@)
205 */
206unsigned long CRTDLL_strtoul(const char* nptr, char** endptr, int base)
207{
208 /* Access nptr to emulate CRTDLL exception behavior */
209 (void)*(volatile char*)nptr;
210 return strtoul(nptr, endptr, base);
211}
212
213/*********************************************************************
214 * wcstoul (CRTDLL.@)
215 */
216unsigned long CRTDLL_wcstoul(const wchar_t* nptr, wchar_t** endptr, int base)
217{
218 /* Access nptr to emulate CRTDLL exception behavior */
219 (void)*(volatile wchar_t*)nptr;
220 return wcstoul(nptr, endptr, base);
221}
222
223/*********************************************************************
224 * system (CRTDLL.@)
225 */
226int CRTDLL_system(const char* command)
227{
228 if (command != NULL)
229 {
230 errno = 0;
231 }
232 return system(command);
233}
234
235/*********************************************************************
236 * _mbsnbcat (CRTDLL.@)
237 */
238unsigned char* CRTDLL__mbsnbcat(unsigned char* dest, const unsigned char* src, size_t n)
239{
240 if (n)
241 {
242 /* Access both buffers to emulate CRTDLL exception behavior */
243 (void)*(volatile char*)dest;
244 (void)*(volatile char*)src;
245 }
246
247 return _mbsnbcat(dest, src, n);
248}
249
250/*********************************************************************
251 * _mbsncat (CRTDLL.@)
252 */
253unsigned char* CRTDLL__mbsncat(unsigned char* dest, const unsigned char* src, size_t n)
254{
255 if (n)
256 {
257 /* Access both buffers to emulate CRTDLL exception behavior */
258 (void)*(volatile char*)dest;
259 (void)*(volatile char*)src;
260 }
261
262 return _mbsncat(dest, src, n);
263}
264
265/*********************************************************************
266 * _vsnprintf (CRTDLL.@)
267 */
268int CRTDLL__vsnprintf(char* buffer, size_t count, const char* format, va_list argptr)
269{
270 (void)*(volatile char*)format;
271 if (count)
272 {
273 (void)*(volatile char*)buffer;
274 }
275 int ret = _vsnprintf(buffer, count, format, argptr);
276 if (ret > (int)count)
277 ret = -1;
278 errno = 0;;
279 return ret;
280}
281
282/*********************************************************************
283 * _snprintf (CRTDLL.@)
284 */
285int CRTDLL__snprintf(char* buffer, size_t count, const char* format, ...)
286{
288 int ret;
291 va_end(args);
292 return ret;
293}
294
295/*********************************************************************
296 * _vsnwprintf (CRTDLL.@)
297 */
298int CRTDLL__vsnwprintf(wchar_t* buffer, size_t count, const wchar_t* format, va_list argptr)
299{
300 (void)*(volatile wchar_t*)format;
301 int ret = _vsnwprintf(buffer, count, format, argptr);
302 if ((ret > (int)count) || !buffer)
303 ret = -1;
304 errno = 0;;
305 return ret;
306}
307
308
309/* Dummy for rand_s, not used. */
311WINAPI
313{
314 assert(FALSE);
315 return 0;
316}
317
318
319/* EOF */
#define _mbsnbcat
#define _mbsncat
unsigned char BOOLEAN
Definition: actypes.h:127
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
unsigned int CRTDLL__osminor_dll
Definition: dllmain.c:36
unsigned char * CRTDLL__mbsstr(const unsigned char *Str, const unsigned char *Substr)
Definition: dllmain.c:178
unsigned long CRTDLL_strtoul(const char *nptr, char **endptr, int base)
Definition: dllmain.c:206
unsigned int CRTDLL__cpumode_dll
Definition: dllmain.c:34
int CRTDLL_sprintf(char *buffer, const char *format,...)
Definition: dllmain.c:188
static void convert_struct_stat(struct crtdll_stat *dst, const struct _stat *src)
Definition: dllmain.c:66
int CRTDLL__vsnwprintf(wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr)
Definition: dllmain.c:298
char ** __initenv
unsigned int CRTDLL__baseminor_dll
Definition: dllmain.c:32
wchar_t ** __winitenv
wchar_t ** _wenviron
void __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: data.c:579
void __GetMainArgs(int *argc, char ***argv, char ***envp, int expand_wildcards)
Definition: dllmain.c:85
int CRTDLL__vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
Definition: dllmain.c:268
unsigned int CRTDLL__osversion_dll
Definition: dllmain.c:38
int CRTDLL__snprintf(char *buffer, size_t count, const char *format,...)
Definition: dllmain.c:285
unsigned int CRTDLL__basemajor_dll
Definition: dllmain.c:31
unsigned int CRTDLL__baseversion_dll
Definition: dllmain.c:33
unsigned int CRTDLL__osmajor_dll
Definition: dllmain.c:35
int CRTDLL_system(const char *command)
Definition: dllmain.c:226
unsigned int CRTDLL__osmode_dll
Definition: dllmain.c:37
unsigned char * CRTDLL__mbsncat(unsigned char *dest, const unsigned char *src, size_t n)
Definition: dllmain.c:253
short crtdll_dev_t
Definition: dllmain.c:48
unsigned char * CRTDLL__mbsnbcat(unsigned char *dest, const unsigned char *src, size_t n)
Definition: dllmain.c:238
unsigned long CRTDLL_wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: dllmain.c:216
BOOLEAN WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
Definition: dllmain.c:312
char ** _environ
int _fileinfo_dll
Definition: dllmain.c:39
int CRTDLL__stat(const char *path, struct crtdll_stat *buf)
Definition: dllmain.c:109
int CRTDLL__fstat(int fd, struct crtdll_stat *buf)
Definition: dllmain.c:95
MonoAssembly int argc
Definition: metahost.c:107
#define assert(_expr)
Definition: assert.h:32
__time32_t time_t
Definition: corecrt.h:228
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
#define errno
Definition: errno.h:120
_ACRTIMP int __cdecl system(const char *)
Definition: process.c:1297
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl vsprintf(char *, const char *, va_list) __WINE_CRT_PRINTF_ATTR(2
_ACRTIMP __msvcrt_ulong __cdecl strtoul(const char *, char **, int)
Definition: string.c:1859
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3415
_ACRTIMP size_t __cdecl strspn(const char *, const char *)
Definition: string.c:3515
int _off_t
Definition: stat.h:31
unsigned short _ino_t
Definition: stat.h:26
char * va_list
Definition: vadefs.h:50
return ret
Definition: mutex.c:146
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
GLenum src
Definition: glext.h:6340
GLuint buffer
Definition: glext.h:5915
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
#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
#define _vsnwprintf
Definition: _vsnwprintf.c:28
static char * dest
Definition: rtl.c:135
#define argv
Definition: mplay32.c:18
const WCHAR * str
#define _stat
Definition: stat.h:146
#define _fstat
Definition: stat.h:144
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
XML_HIDDEN void xmlParserErrors const char const xmlChar * str1
Definition: parser.h:35
static int fd
Definition: io.c:51
#define args
Definition: format.c:66
Definition: stat.h:52
Definition: match.c:390
short st_nlink
Definition: dllmain.c:55
short st_gid
Definition: dllmain.c:57
unsigned short st_mode
Definition: dllmain.c:54
time_t st_ctime
Definition: dllmain.c:62
_ino_t st_ino
Definition: dllmain.c:53
time_t st_mtime
Definition: dllmain.c:61
time_t st_atime
Definition: dllmain.c:60
short st_uid
Definition: dllmain.c:56
_off_t st_size
Definition: dllmain.c:59
crtdll_dev_t st_dev
Definition: dllmain.c:52
crtdll_dev_t st_rdev
Definition: dllmain.c:58
Definition: format.c:58
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define _vsnprintf
Definition: xmlstorage.h:202