Release 6.15.
[wine.git] / dlls / msvcrt / msvcrt.h
blobad366a74d8684c15630ef83cfd997873a0f49d35
1 /*
2 * Copyright 2001 Jon Griffiths
3 * Copyright 2004 Dimitrie O. Paun
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef __WINE_MSVCRT_H
21 #define __WINE_MSVCRT_H
23 #include <errno.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #define _NO_CRT_STDIO_INLINE
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <wchar.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #undef strncpy
34 #undef wcsncpy
36 extern BOOL sse2_supported DECLSPEC_HIDDEN;
38 #define DBL80_MAX_10_EXP 4932
39 #define DBL80_MIN_10_EXP -4951
41 typedef void (__cdecl *terminate_function)(void);
42 typedef void (__cdecl *unexpected_function)(void);
43 typedef void (__cdecl *_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
44 void __cdecl terminate(void);
46 typedef void (__cdecl *MSVCRT_security_error_handler)(int, void *);
48 typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */
50 typedef struct __lc_time_data {
51 union {
52 const char *str[43];
53 struct {
54 const char *short_wday[7];
55 const char *wday[7];
56 const char *short_mon[12];
57 const char *mon[12];
58 const char *am;
59 const char *pm;
60 const char *short_date;
61 const char *date;
62 const char *time;
63 } names;
64 } str;
65 #if _MSVCR_VER < 110
66 LCID lcid;
67 #endif
68 int unk;
69 int refcount;
70 #if _MSVCR_VER == 0 || _MSVCR_VER >= 100
71 union {
72 const wchar_t *wstr[43];
73 struct {
74 const wchar_t *short_wday[7];
75 const wchar_t *wday[7];
76 const wchar_t *short_mon[12];
77 const wchar_t *mon[12];
78 const wchar_t *am;
79 const wchar_t *pm;
80 const wchar_t *short_date;
81 const wchar_t *date;
82 const wchar_t *time;
83 } names;
84 } wstr;
85 #endif
86 #if _MSVCR_VER >= 110
87 const wchar_t *locname;
88 #endif
89 char data[1];
90 } __lc_time_data;
92 typedef struct threadmbcinfostruct {
93 int refcount;
94 int mbcodepage;
95 int ismbcodepage;
96 int mblcid;
97 unsigned short mbulinfo[6];
98 unsigned char mbctype[257];
99 unsigned char mbcasemap[256];
100 } threadmbcinfo;
102 typedef struct _frame_info
104 void *object;
105 struct _frame_info *next;
106 } frame_info;
108 typedef struct
110 frame_info frame_info;
111 EXCEPTION_RECORD *rec;
112 CONTEXT *context;
113 } cxx_frame_info;
115 frame_info* __cdecl _CreateFrameInfo(frame_info *fi, void *obj);
116 BOOL __cdecl __CxxRegisterExceptionObject(EXCEPTION_POINTERS*, cxx_frame_info*);
117 void __cdecl __CxxUnregisterExceptionObject(cxx_frame_info*, BOOL);
118 void CDECL __DestructExceptionObject(EXCEPTION_RECORD*);
120 /* TLS data */
121 extern DWORD msvcrt_tls_index DECLSPEC_HIDDEN;
123 #define LOCALE_FREE 0x1
124 #define LOCALE_THREAD 0x2
126 /* Keep in sync with msvcr90/tests/msvcr90.c */
127 struct __thread_data {
128 DWORD tid;
129 HANDLE handle;
130 int thread_errno;
131 __msvcrt_ulong thread_doserrno;
132 int unk1;
133 unsigned int random_seed; /* seed for rand() */
134 char *strtok_next; /* next ptr for strtok() */
135 wchar_t *wcstok_next; /* next ptr for wcstok() */
136 unsigned char *mbstok_next; /* next ptr for mbstok() */
137 char *strerror_buffer; /* buffer for strerror */
138 wchar_t *wcserror_buffer; /* buffer for wcserror */
139 char *tmpnam_buffer; /* buffer for tmpname() */
140 wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */
141 void *unk2[2];
142 char *asctime_buffer; /* buffer for asctime */
143 wchar_t *wasctime_buffer; /* buffer for wasctime */
144 struct tm *time_buffer; /* buffer for localtime/gmtime */
145 char *efcvt_buffer; /* buffer for ecvt/fcvt */
146 int unk3[2];
147 void *unk4[3];
148 EXCEPTION_POINTERS *xcptinfo;
149 int fpecode;
150 pthreadmbcinfo mbcinfo;
151 pthreadlocinfo locinfo;
152 int locale_flags;
153 int unk5[1];
154 terminate_function terminate_handler;
155 unexpected_function unexpected_handler;
156 _se_translator_function se_translator; /* preserve offset to exc_record and processing_throw */
157 void *unk6;
158 EXCEPTION_RECORD *exc_record;
159 CONTEXT *ctx_record;
160 int processing_throw;
161 frame_info *frame_info_head;
162 void *unk8[6];
163 LCID cached_lcid;
164 BOOL cached_sname;
165 int unk9[2];
166 DWORD cached_cp;
167 char cached_locale[131];
168 void *unk10[100];
169 #if _MSVCR_VER >= 140
170 _invalid_parameter_handler invalid_parameter_handler;
171 HMODULE module;
172 #endif
175 typedef struct __thread_data thread_data_t;
177 extern thread_data_t *CDECL msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
179 LCID locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN;
180 extern _locale_t MSVCRT_locale DECLSPEC_HIDDEN;
181 extern __lc_time_data cloc_time_data DECLSPEC_HIDDEN;
182 extern unsigned int MSVCRT___lc_codepage;
183 extern int MSVCRT___lc_collate_cp;
184 extern WORD MSVCRT__ctype [257];
185 extern BOOL initial_locale DECLSPEC_HIDDEN;
186 extern WORD *MSVCRT__pwctype;
188 void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
189 #if _MSVCR_VER >= 80
190 typedef enum {
191 EXCEPTION_BAD_ALLOC,
192 #if _MSVCR_VER >= 100
193 EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR,
194 EXCEPTION_IMPROPER_LOCK,
195 EXCEPTION_INVALID_SCHEDULER_POLICY_KEY,
196 EXCEPTION_INVALID_SCHEDULER_POLICY_VALUE,
197 EXCEPTION_INVALID_SCHEDULER_POLICY_THREAD_SPECIFICATION,
198 EXCEPTION_IMPROPER_SCHEDULER_ATTACH,
199 EXCEPTION_IMPROPER_SCHEDULER_DETACH,
200 #endif
201 } exception_type;
202 void throw_exception(exception_type, HRESULT, const char*) DECLSPEC_HIDDEN;
203 #endif
205 void __cdecl _purecall(void);
206 void __cdecl _amsg_exit(int errnum);
208 extern char **MSVCRT__environ;
209 extern wchar_t **MSVCRT__wenviron;
211 extern char ** msvcrt_SnapshotOfEnvironmentA(char **) DECLSPEC_HIDDEN;
212 extern wchar_t ** msvcrt_SnapshotOfEnvironmentW(wchar_t **) DECLSPEC_HIDDEN;
214 wchar_t *msvcrt_wstrdupa(const char *) DECLSPEC_HIDDEN;
216 extern unsigned int MSVCRT__commode;
218 /* FIXME: This should be declared in new.h but it's not an extern "C" so
219 * it would not be much use anyway. Even for Winelib applications.
221 void* __cdecl operator_new(size_t);
222 void __cdecl operator_delete(void*);
223 int __cdecl _set_new_mode(int mode);
225 typedef void* (__cdecl *malloc_func_t)(size_t);
226 typedef void (__cdecl *free_func_t)(void*);
228 /* Setup and teardown multi threaded locks */
229 extern void msvcrt_init_mt_locks(void) DECLSPEC_HIDDEN;
230 extern void msvcrt_free_locks(void) DECLSPEC_HIDDEN;
232 extern void msvcrt_init_exception(void*) DECLSPEC_HIDDEN;
233 extern BOOL msvcrt_init_locale(void) DECLSPEC_HIDDEN;
234 extern void msvcrt_init_math(void*) DECLSPEC_HIDDEN;
235 extern void msvcrt_init_io(void) DECLSPEC_HIDDEN;
236 extern void msvcrt_free_io(void) DECLSPEC_HIDDEN;
237 extern void msvcrt_free_console(void) DECLSPEC_HIDDEN;
238 extern void msvcrt_init_args(void) DECLSPEC_HIDDEN;
239 extern void msvcrt_free_args(void) DECLSPEC_HIDDEN;
240 extern void msvcrt_init_signals(void) DECLSPEC_HIDDEN;
241 extern void msvcrt_free_signals(void) DECLSPEC_HIDDEN;
242 extern void msvcrt_free_popen_data(void) DECLSPEC_HIDDEN;
243 extern BOOL msvcrt_init_heap(void) DECLSPEC_HIDDEN;
244 extern void msvcrt_destroy_heap(void) DECLSPEC_HIDDEN;
245 extern void msvcrt_init_clock(void) DECLSPEC_HIDDEN;
247 #if _MSVCR_VER >= 100
248 extern void msvcrt_init_scheduler(void*) DECLSPEC_HIDDEN;
249 extern void msvcrt_free_scheduler(void) DECLSPEC_HIDDEN;
250 extern void msvcrt_free_scheduler_thread(void) DECLSPEC_HIDDEN;
251 #endif
253 extern unsigned msvcrt_create_io_inherit_block(WORD*, BYTE**) DECLSPEC_HIDDEN;
255 /* run-time error codes */
256 #define _RT_STACK 0
257 #define _RT_NULLPTR 1
258 #define _RT_FLOAT 2
259 #define _RT_INTDIV 3
260 #define _RT_EXECMEM 5
261 #define _RT_EXECFORM 6
262 #define _RT_EXECENV 7
263 #define _RT_SPACEARG 8
264 #define _RT_SPACEENV 9
265 #define _RT_ABORT 10
266 #define _RT_NPTR 12
267 #define _RT_FPTR 13
268 #define _RT_BREAK 14
269 #define _RT_INT 15
270 #define _RT_THREAD 16
271 #define _RT_LOCK 17
272 #define _RT_HEAP 18
273 #define _RT_OPENCON 19
274 #define _RT_QWIN 20
275 #define _RT_NOMAIN 21
276 #define _RT_NONCONT 22
277 #define _RT_INVALDISP 23
278 #define _RT_ONEXIT 24
279 #define _RT_PUREVIRT 25
280 #define _RT_STDIOINIT 26
281 #define _RT_LOWIOINIT 27
282 #define _RT_HEAPINIT 28
283 #define _RT_DOMAIN 120
284 #define _RT_SING 121
285 #define _RT_TLOSS 122
286 #define _RT_CRNL 252
287 #define _RT_BANNER 255
289 extern FILE MSVCRT__iob[];
291 #define MSVCRT_NO_CONSOLE_FD (-2)
292 #define MSVCRT_NO_CONSOLE ((HANDLE)MSVCRT_NO_CONSOLE_FD)
294 #define MSVCRT_stdin (MSVCRT__iob+STDIN_FILENO)
295 #define MSVCRT_stdout (MSVCRT__iob+STDOUT_FILENO)
296 #define MSVCRT_stderr (MSVCRT__iob+STDERR_FILENO)
298 /* internal file._flag flags */
299 #define MSVCRT__USERBUF 0x0100
300 #define MSVCRT__IOCOMMIT 0x4000
302 #define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF)
304 _locale_t CDECL get_current_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
305 void CDECL free_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
306 pthreadlocinfo CDECL get_locinfo(void) DECLSPEC_HIDDEN;
307 pthreadmbcinfo CDECL get_mbcinfo(void) DECLSPEC_HIDDEN;
308 threadmbcinfo* create_mbcinfo(int, LCID, threadmbcinfo*) DECLSPEC_HIDDEN;
309 void free_locinfo(pthreadlocinfo) DECLSPEC_HIDDEN;
310 void free_mbcinfo(pthreadmbcinfo) DECLSPEC_HIDDEN;
311 int __cdecl __crtLCMapStringA(LCID, DWORD, const char*, int, char*, int, unsigned int, int) DECLSPEC_HIDDEN;
313 enum fpmod {
314 FP_ROUND_ZERO, /* only used when dropped part contains only zeros */
315 FP_ROUND_DOWN,
316 FP_ROUND_EVEN,
317 FP_ROUND_UP,
318 FP_VAL_INFINITY,
319 FP_VAL_NAN
322 struct fpnum {
323 int sign;
324 int exp;
325 ULONGLONG m;
326 enum fpmod mod;
328 struct fpnum fpnum_parse(wchar_t (*)(void*), void (*)(void*),
329 void*, pthreadlocinfo, BOOL) DECLSPEC_HIDDEN;
330 int fpnum_double(struct fpnum*, double*) DECLSPEC_HIDDEN;
331 /* Maybe one day we'll enable the invalid parameter handlers with the full set of information (msvcrXXd)
332 * #define MSVCRT_INVALID_PMT(x) MSVCRT_call_invalid_parameter_handler(x, __FUNCTION__, __FILE__, __LINE__, 0)
333 * #define MSVCRT_CHECK_PMT(x) ((x) ? TRUE : MSVCRT_INVALID_PMT(#x),FALSE)
334 * Until this is done, just keep the same semantics for CHECK_PMT(), but without generating / sending
335 * any information
336 * NB : MSVCRT_call_invalid_parameter_handler is a wrapper around _invalid_parameter in order
337 * to do the Ansi to Unicode transformation
339 #define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
340 #define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), FALSE))
341 #define MSVCRT_CHECK_PMT(x) MSVCRT_CHECK_PMT_ERR((x), EINVAL)
343 typedef int (*puts_clbk_a)(void*, int, const char*);
344 typedef int (*puts_clbk_w)(void*, int, const wchar_t*);
345 typedef union _printf_arg
347 void *get_ptr;
348 int get_int;
349 LONGLONG get_longlong;
350 double get_double;
351 } printf_arg;
352 typedef printf_arg (*args_clbk)(void*, int, int, __ms_va_list*);
353 int pf_printf_a(puts_clbk_a, void*, const char*, _locale_t,
354 DWORD, args_clbk, void*, __ms_va_list*) DECLSPEC_HIDDEN;
355 int pf_printf_w(puts_clbk_w, void*, const wchar_t*, _locale_t,
356 DWORD, args_clbk, void*, __ms_va_list*) DECLSPEC_HIDDEN;
357 int create_positional_ctx_a(void*, const char*, __ms_va_list) DECLSPEC_HIDDEN;
358 int create_positional_ctx_w(void*, const wchar_t*, __ms_va_list) DECLSPEC_HIDDEN;
359 printf_arg arg_clbk_valist(void*, int, int, __ms_va_list*) DECLSPEC_HIDDEN;
360 printf_arg arg_clbk_positional(void*, int, int, __ms_va_list*) DECLSPEC_HIDDEN;
362 extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
364 /* __unDName/__unDNameEx flags */
365 #define UNDNAME_COMPLETE (0x0000)
366 #define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) /* Don't show __ in calling convention */
367 #define UNDNAME_NO_MS_KEYWORDS (0x0002) /* Don't show calling convention at all */
368 #define UNDNAME_NO_FUNCTION_RETURNS (0x0004) /* Don't show function/method return value */
369 #define UNDNAME_NO_ALLOCATION_MODEL (0x0008)
370 #define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010)
371 #define UNDNAME_NO_MS_THISTYPE (0x0020)
372 #define UNDNAME_NO_CV_THISTYPE (0x0040)
373 #define UNDNAME_NO_THISTYPE (0x0060)
374 #define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) /* Don't show access specifier (public/protected/private) */
375 #define UNDNAME_NO_THROW_SIGNATURES (0x0100)
376 #define UNDNAME_NO_MEMBER_TYPE (0x0200) /* Don't show static/virtual specifier */
377 #define UNDNAME_NO_RETURN_UDT_MODEL (0x0400)
378 #define UNDNAME_32_BIT_DECODE (0x0800)
379 #define UNDNAME_NAME_ONLY (0x1000) /* Only report the variable/method name */
380 #define UNDNAME_NO_ARGUMENTS (0x2000) /* Don't show method arguments */
381 #define UNDNAME_NO_SPECIAL_SYMS (0x4000)
382 #define UNDNAME_NO_COMPLEX_TYPE (0x8000)
384 #define UCRTBASE_PRINTF_MASK ( \
385 _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION | \
386 _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR | \
387 _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS | \
388 _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY | \
389 _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS | \
390 _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING )
392 #define MSVCRT_PRINTF_POSITIONAL_PARAMS (0x0100)
393 #define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER (0x0200)
395 #define UCRTBASE_SCANF_MASK ( \
396 _CRT_INTERNAL_SCANF_SECURECRT | \
397 _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS | \
398 _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY )
400 #define COOPERATIVE_TIMEOUT_INFINITE ((unsigned int)-1)
401 #define COOPERATIVE_WAIT_TIMEOUT ~0
403 #define INHERIT_THREAD_PRIORITY 0xF000
405 #endif /* __WINE_MSVCRT_H */