rpcrt4: Pass in a maximum variance value to ReadVariance to allow us
[wine] / dlls / crtdll / crtdll_main.c
CommitLineData
8cc3a5e4 1/*
0b47b289 2 * Old C RunTime DLL - All functionality is provided by msvcrt.
8cc3a5e4 3 *
d3576a9f 4 * Copyright 2000 Jon Griffiths
0799c1a7
AJ
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
360a3f91 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
8cc3a5e4 19 */
945bb366 20
7a4e5997 21#include "config.h"
46304a73 22
14e3b19c 23#include <stdarg.h>
821d4c46
FG
24#ifdef HAVE_SYS_STAT_H
25# include <sys/stat.h>
26#endif
46304a73 27
0b47b289
JG
28#include "windef.h"
29#include "winbase.h"
46304a73 30
0799c1a7 31#include "wine/debug.h"
cc08b38f 32
0799c1a7 33WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
8cc3a5e4 34
91ab1208 35/* from msvcrt */
d81ce0fc
FG
36extern void __getmainargs( int *argc, char ***argv, char ***envp,
37 int expand_wildcards, int *new_mode );
91ab1208 38
0b47b289
JG
39/* The following data items are not exported from msvcrt */
40unsigned int CRTDLL__basemajor_dll;
41unsigned int CRTDLL__baseminor_dll;
42unsigned int CRTDLL__baseversion_dll;
43unsigned int CRTDLL__cpumode_dll;
44unsigned int CRTDLL__osmajor_dll;
45unsigned int CRTDLL__osminor_dll;
46unsigned int CRTDLL__osmode_dll;
47unsigned int CRTDLL__osversion_dll;
e371e682 48
945bb366
AJ
49/* dev_t is a short in crtdll but an unsigned int in msvcrt */
50typedef short crtdll_dev_t;
51
52struct crtdll_stat
53{
54 crtdll_dev_t st_dev;
55 _ino_t st_ino;
56 unsigned short st_mode;
57 short st_nlink;
58 short st_uid;
59 short st_gid;
60 crtdll_dev_t st_rdev;
2aed5d77
AJ
61 _off_t st_size;
62 time_t st_atime;
63 time_t st_mtime;
64 time_t st_ctime;
945bb366
AJ
65};
66
67/* convert struct _stat from crtdll format to msvcrt format */
68static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
69{
70 dst->st_dev = src->st_dev;
71 dst->st_ino = src->st_ino;
72 dst->st_mode = src->st_mode;
73 dst->st_nlink = src->st_nlink;
74 dst->st_uid = src->st_uid;
75 dst->st_gid = src->st_gid;
76 dst->st_rdev = src->st_rdev;
77 dst->st_size = src->st_size;
78 dst->st_atime = src->st_atime;
79 dst->st_mtime = src->st_mtime;
80 dst->st_ctime = src->st_ctime;
81}
82
83
090e2d87 84/*********************************************************************
1e1313d5 85 * DllMain (CRTDLL.init)
090e2d87 86 */
1e1313d5 87BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
090e2d87 88{
b34fb35b 89 TRACE("(%p,%ld,%p)\n",hinstDLL,fdwReason,lpvReserved);
88e24537 90
0b47b289 91 if (fdwReason == DLL_PROCESS_ATTACH)
88e24537 92 {
0b47b289 93 DWORD version = GetVersion();
4e1ef0c1
DT
94
95 DisableThreadLibraryCalls(hinstDLL);
96
0b47b289
JG
97 CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
98 CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
99 CRTDLL__baseversion_dll = (version >> 16);
100 CRTDLL__cpumode_dll = 1; /* FIXME */
101 CRTDLL__osmajor_dll = (version>>8) & 0xFF;
102 CRTDLL__osminor_dll = (version & 0xFF);
103 CRTDLL__osmode_dll = 1; /* FIXME */
104 CRTDLL__osversion_dll = (version & 0xFFFF);
88e24537 105 }
0b47b289 106 return TRUE;
88e24537 107}
91ab1208
AJ
108
109
110/*********************************************************************
111 * __GetMainArgs (CRTDLL.@)
112 */
d81ce0fc 113void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
91ab1208 114{
3fe81b46 115 int new_mode = 0;
d81ce0fc 116 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
91ab1208 117}
945bb366
AJ
118
119
120/*********************************************************************
121 * _fstat (CRTDLL.@)
122 */
123int CRTDLL__fstat(int fd, struct crtdll_stat* buf)
124{
4c5d562c 125 extern int _fstat(int,struct _stat*);
945bb366
AJ
126 struct _stat st;
127 int ret;
128
129 if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
130 return ret;
131}
132
133
134/*********************************************************************
135 * _stat (CRTDLL.@)
136 */
137int CRTDLL__stat(const char* path, struct crtdll_stat * buf)
138{
4c5d562c 139 extern int _stat(const char*,struct _stat*);
945bb366
AJ
140 struct _stat st;
141 int ret;
142
143 if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
144 return ret;
145}
d0c87253
AJ
146
147
148/*********************************************************************
149 * _strdec (CRTDLL.@)
150 */
151char *_strdec(const char *str1, const char *str2)
152{
153 return (char *)(str2 - 1);
154}
155
156
157/*********************************************************************
158 * _strinc (CRTDLL.@)
159 */
160char *_strinc(const char *str)
161{
162 return (char *)(str + 1);
163}
164
165
166/*********************************************************************
167 * _strncnt (CRTDLL.@)
168 */
169size_t _strncnt(const char *str, size_t maxlen)
170{
171 size_t len = strlen(str);
172 return (len > maxlen) ? maxlen : len;
173}
174
175
176/*********************************************************************
177 * _strnextc (CRTDLL.@)
178 */
179unsigned int _strnextc(const char *str)
180{
181 return (unsigned int)str[0];
182}
183
184
185/*********************************************************************
186 * _strninc (CRTDLL.@)
187 */
188char *_strninc(const char *str, size_t len)
189{
190 return (char *)(str + len);
191}
192
193
194/*********************************************************************
195 * _strspnp (CRTDLL.@)
196 */
197char *_strspnp( const char *str1, const char *str2)
198{
199 str1 += strspn( str1, str2 );
200 return *str1 ? (char*)str1 : NULL;
201}