1 | /*
|
---|
2 | * Old C RunTime DLL - All functionality is provided by msvcrt.
|
---|
3 | *
|
---|
4 | * Copyright 2000 Jon Griffiths
|
---|
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
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 | #include "windef.h"
|
---|
23 | #include "winbase.h"
|
---|
24 | #define USE_MSVCRT_PREFIX
|
---|
25 | #include "msvcrt/sys/stat.h"
|
---|
26 | #include "wine/debug.h"
|
---|
27 |
|
---|
28 | WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
|
---|
29 |
|
---|
30 | /* from msvcrt */
|
---|
31 | extern void __getmainargs( int *argc, char ***argv, char ***envp,
|
---|
32 | int expand_wildcards, int *new_mode );
|
---|
33 |
|
---|
34 | /* The following data items are not exported from msvcrt */
|
---|
35 | unsigned int CRTDLL__basemajor_dll;
|
---|
36 | unsigned int CRTDLL__baseminor_dll;
|
---|
37 | unsigned int CRTDLL__baseversion_dll;
|
---|
38 | unsigned int CRTDLL__cpumode_dll;
|
---|
39 | unsigned int CRTDLL__osmajor_dll;
|
---|
40 | unsigned int CRTDLL__osminor_dll;
|
---|
41 | unsigned int CRTDLL__osmode_dll;
|
---|
42 | unsigned int CRTDLL__osversion_dll;
|
---|
43 |
|
---|
44 | /* dev_t is a short in crtdll but an unsigned int in msvcrt */
|
---|
45 | typedef short crtdll_dev_t;
|
---|
46 |
|
---|
47 | struct crtdll_stat
|
---|
48 | {
|
---|
49 | crtdll_dev_t st_dev;
|
---|
50 | _ino_t st_ino;
|
---|
51 | unsigned short st_mode;
|
---|
52 | short st_nlink;
|
---|
53 | short st_uid;
|
---|
54 | short st_gid;
|
---|
55 | crtdll_dev_t st_rdev;
|
---|
56 | MSVCRT(_off_t) st_size;
|
---|
57 | MSVCRT(time_t) st_atime;
|
---|
58 | MSVCRT(time_t) st_mtime;
|
---|
59 | MSVCRT(time_t) st_ctime;
|
---|
60 | };
|
---|
61 |
|
---|
62 | /* convert struct _stat from crtdll format to msvcrt format */
|
---|
63 | static void convert_struct_stat( struct crtdll_stat *dst, const struct _stat *src )
|
---|
64 | {
|
---|
65 | dst->st_dev = src->st_dev;
|
---|
66 | dst->st_ino = src->st_ino;
|
---|
67 | dst->st_mode = src->st_mode;
|
---|
68 | dst->st_nlink = src->st_nlink;
|
---|
69 | dst->st_uid = src->st_uid;
|
---|
70 | dst->st_gid = src->st_gid;
|
---|
71 | dst->st_rdev = src->st_rdev;
|
---|
72 | dst->st_size = src->st_size;
|
---|
73 | dst->st_atime = src->st_atime;
|
---|
74 | dst->st_mtime = src->st_mtime;
|
---|
75 | dst->st_ctime = src->st_ctime;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /*********************************************************************
|
---|
80 | * DllMain (CRTDLL.init)
|
---|
81 | */
|
---|
82 | BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
|
---|
83 | {
|
---|
84 | TRACE("CRTDLL32(%p,%ld,%p)\n",hinstDLL,fdwReason,lpvReserved);
|
---|
85 |
|
---|
86 | if (fdwReason == DLL_PROCESS_ATTACH)
|
---|
87 | {
|
---|
88 | DWORD version;// = GetVersion();
|
---|
89 | CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
|
---|
90 | CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
|
---|
91 | CRTDLL__baseversion_dll = (version >> 16);
|
---|
92 | CRTDLL__cpumode_dll = 1; /* FIXME */
|
---|
93 | CRTDLL__osmajor_dll = (version>>8) & 0xFF;
|
---|
94 | CRTDLL__osminor_dll = (version & 0xFF);
|
---|
95 | CRTDLL__osmode_dll = 1; /* FIXME */
|
---|
96 | CRTDLL__osversion_dll = (version & 0xFFFF);
|
---|
97 | }
|
---|
98 | return TRUE;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /*********************************************************************
|
---|
103 | * __GetMainArgs (CRTDLL.@)
|
---|
104 | */
|
---|
105 | void __GetMainArgs( int *argc, char ***argv, char ***envp, int expand_wildcards )
|
---|
106 | {
|
---|
107 | int new_mode = 0;
|
---|
108 | __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | /*********************************************************************
|
---|
113 | * _fstat (CRTDLL.@)
|
---|
114 | */
|
---|
115 | int CRTDLL__fstat(int fd, struct crtdll_stat* buf)
|
---|
116 | {
|
---|
117 | extern int _fstat(int,struct _stat*);
|
---|
118 | struct _stat st;
|
---|
119 | int ret;
|
---|
120 |
|
---|
121 | if (!(ret = _fstat( fd, &st ))) convert_struct_stat( buf, &st );
|
---|
122 | return ret;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /*********************************************************************
|
---|
127 | * _stat (CRTDLL.@)
|
---|
128 | */
|
---|
129 | int CRTDLL__stat(const char* path, struct crtdll_stat * buf)
|
---|
130 | {
|
---|
131 | extern int _stat(const char*,struct _stat*);
|
---|
132 | struct _stat st;
|
---|
133 | int ret;
|
---|
134 |
|
---|
135 | if (!(ret = _stat( path, &st ))) convert_struct_stat( buf, &st );
|
---|
136 | return ret;
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | /*********************************************************************
|
---|
141 | * _strdec (CRTDLL.@)
|
---|
142 | */
|
---|
143 | char *_strdec(const char *str1, const char *str2)
|
---|
144 | {
|
---|
145 | return (char *)(str2 - 1);
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | /*********************************************************************
|
---|
150 | * _strinc (CRTDLL.@)
|
---|
151 | */
|
---|
152 | char *_strinc(const char *str)
|
---|
153 | {
|
---|
154 | return (char *)(str + 1);
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | /*********************************************************************
|
---|
159 | * _strncnt (CRTDLL.@)
|
---|
160 | */
|
---|
161 | size_t _strncnt(const char *str, size_t maxlen)
|
---|
162 | {
|
---|
163 | size_t len = strlen(str);
|
---|
164 | return (len > maxlen) ? maxlen : len;
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | /*********************************************************************
|
---|
169 | * _strnextc (CRTDLL.@)
|
---|
170 | */
|
---|
171 | unsigned int _strnextc(const char *str)
|
---|
172 | {
|
---|
173 | return (unsigned int)str[0];
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | /*********************************************************************
|
---|
178 | * _strninc (CRTDLL.@)
|
---|
179 | */
|
---|
180 | char *_strninc(const char *str, size_t len)
|
---|
181 | {
|
---|
182 | return (char *)(str + len);
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | /*********************************************************************
|
---|
187 | * _strspnp (CRTDLL.@)
|
---|
188 | */
|
---|
189 | char *_strspnp( const char *str1, const char *str2)
|
---|
190 | {
|
---|
191 | str1 += strspn( str1, str2 );
|
---|
192 | return *str1 ? (char*)str1 : NULL;
|
---|
193 | }
|
---|