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