msvcrt: Added macro to ease implementation of so called secure (_s postfix) APIs.
[wine] / dlls / msvcrt / msvcrt.h
1 /*
2  * Copyright 2001 Jon Griffiths
3  * Copyright 2004 Dimitrie O. Paun
4  *
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.
9  *
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.
14  *
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
18  *
19  * NOTES
20  *   Naming conventions
21  *      - Symbols are prefixed with MSVCRT_ if they conflict
22  *        with libc symbols
23  *      - Internal symbols are usually prefixed by msvcrt_.
24  *      - Exported symbols that are not present in the public
25  *        headers are usually kept the same as the original.
26  *   Other conventions
27  *      - To avoid conflicts with the standard C library,
28  *        no msvcrt headers are included in the implementation.
29  *      - Instead, symbols are duplicated here, prefixed with 
30  *        MSVCRT_, as explained above.
31  *      - To avoid inconsistencies, a test for each symbol is
32  *        added into tests/headers.c. Please always add a
33  *        corresponding test when you add a new symbol!
34  */
35
36 #ifndef __WINE_MSVCRT_H
37 #define __WINE_MSVCRT_H
38
39 #include <stdarg.h>
40
41 #include "windef.h"
42 #include "winbase.h"
43
44 #define MSVCRT_LONG_MAX    0x7fffffffL
45 #define MSVCRT_ULONG_MAX   0xffffffffUL
46 #define MSVCRT_I64_MAX    (((__int64)0x7fffffff << 32) | 0xffffffff)
47 #define MSVCRT_I64_MIN    (-MSVCRT_I64_MAX-1)
48 #define MSVCRT_UI64_MAX   (((unsigned __int64)0xffffffff << 32) | 0xffffffff)
49
50 #define MSVCRT__MAX_DRIVE  3
51 #define MSVCRT__MAX_DIR    256
52 #define MSVCRT__MAX_FNAME  256
53 #define MSVCRT__MAX_EXT    256
54
55 typedef unsigned short MSVCRT_wchar_t;
56 typedef unsigned short MSVCRT_wint_t;
57 typedef unsigned short MSVCRT_wctype_t;
58 typedef unsigned short MSVCRT__ino_t;
59 typedef unsigned int   MSVCRT__fsize_t;
60 typedef int            MSVCRT_long;
61 typedef unsigned int   MSVCRT_ulong;
62 #ifdef _WIN64
63 typedef unsigned __int64 MSVCRT_size_t;
64 typedef __int64 MSVCRT_intptr_t;
65 typedef unsigned __int64 MSVCRT_uintptr_t;
66 #else
67 typedef unsigned long MSVCRT_size_t;
68 typedef long MSVCRT_intptr_t;
69 typedef unsigned long MSVCRT_uintptr_t;
70 #endif
71 typedef unsigned int   MSVCRT__dev_t;
72 typedef int MSVCRT__off_t;
73 typedef int MSVCRT_clock_t;
74 typedef int MSVCRT___time32_t;
75 typedef __int64 DECLSPEC_ALIGN(8) MSVCRT___time64_t;
76 typedef __int64 DECLSPEC_ALIGN(8) MSVCRT_fpos_t;
77
78 typedef void (*__cdecl MSVCRT_terminate_handler)(void);
79 typedef void (*__cdecl MSVCRT_terminate_function)(void);
80 typedef void (*__cdecl MSVCRT_unexpected_handler)(void);
81 typedef void (*__cdecl MSVCRT_unexpected_function)(void);
82 typedef void (*__cdecl MSVCRT__se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
83 typedef void (*__cdecl MSVCRT__beginthread_start_routine_t)(void *);
84 typedef unsigned int (__stdcall *MSVCRT__beginthreadex_start_routine_t)(void *);
85 typedef int (*__cdecl MSVCRT__onexit_t)(void);
86 typedef void (__cdecl *MSVCRT_invalid_parameter_handler)(const MSVCRT_wchar_t*, const MSVCRT_wchar_t*, const MSVCRT_wchar_t*, unsigned, MSVCRT_uintptr_t);
87 typedef void (__cdecl *MSVCRT_purecall_handler)(void);
88
89 typedef struct {long double x;} MSVCRT__LDOUBLE;
90
91 struct MSVCRT_tm {
92     int tm_sec;
93     int tm_min;
94     int tm_hour;
95     int tm_mday;
96     int tm_mon;
97     int tm_year;
98     int tm_wday;
99     int tm_yday;
100     int tm_isdst;
101 };
102
103
104 /* TLS data */
105 extern DWORD msvcrt_tls_index;
106
107 struct __thread_data {
108     int                             thread_errno;
109     MSVCRT_ulong                    thread_doserrno;
110     unsigned int                    random_seed;        /* seed for rand() */
111     char                           *strtok_next;        /* next ptr for strtok() */
112     unsigned char                  *mbstok_next;        /* next ptr for mbstok() */
113     MSVCRT_wchar_t                 *wcstok_next;        /* next ptr for wcstok() */
114     char                           *efcvt_buffer;       /* buffer for ecvt/fcvt */
115     char                           *asctime_buffer;     /* buffer for asctime */
116     MSVCRT_wchar_t                 *wasctime_buffer;    /* buffer for wasctime */
117     struct MSVCRT_tm                time_buffer;        /* buffer for localtime/gmtime */
118     char                           *strerror_buffer;    /* buffer for strerror */
119     int                             fpecode;
120     MSVCRT_terminate_function       terminate_handler;
121     MSVCRT_unexpected_function      unexpected_handler;
122     MSVCRT__se_translator_function  se_translator;
123     EXCEPTION_RECORD               *exc_record;
124     struct MSVCRT_localeinfo_struct *locale;
125 };
126
127 typedef struct __thread_data thread_data_t;
128
129 extern thread_data_t *msvcrt_get_thread_data(void);
130
131 extern int MSVCRT___lc_codepage;
132 extern int MSVCRT___lc_collate_cp;
133 extern int MSVCRT___mb_cur_max;
134 extern WORD MSVCRT__ctype [257];
135 extern WORD* MSVCRT__pctype;
136
137 void   msvcrt_set_errno(int);
138
139 void __cdecl _purecall(void);
140 void __cdecl _amsg_exit(int errnum);
141
142 extern char **MSVCRT__environ;
143 extern MSVCRT_wchar_t **MSVCRT__wenviron;
144
145 extern char ** msvcrt_SnapshotOfEnvironmentA(char **);
146 extern MSVCRT_wchar_t ** msvcrt_SnapshotOfEnvironmentW(MSVCRT_wchar_t **);
147
148 MSVCRT_wchar_t *msvcrt_wstrdupa(const char *);
149
150 /* FIXME: This should be declared in new.h but it's not an extern "C" so
151  * it would not be much use anyway. Even for Winelib applications.
152  */
153 int __cdecl MSVCRT__set_new_mode(int mode);
154
155 void* __cdecl MSVCRT_operator_new(MSVCRT_size_t);
156 void __cdecl MSVCRT_operator_delete(void*);
157
158 typedef void* (*__cdecl malloc_func_t)(MSVCRT_size_t);
159 typedef void  (*__cdecl free_func_t)(void*);
160
161 extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
162 extern char* __cdecl __unDNameEx(char *,const char*,int,malloc_func_t,free_func_t,void *,unsigned short int);
163
164 /* Setup and teardown multi threaded locks */
165 extern void msvcrt_init_mt_locks(void);
166 extern void msvcrt_free_mt_locks(void);
167
168 extern void msvcrt_init_io(void);
169 extern void msvcrt_free_io(void);
170 extern void msvcrt_init_console(void);
171 extern void msvcrt_free_console(void);
172 extern void msvcrt_init_args(void);
173 extern void msvcrt_free_args(void);
174 extern void msvcrt_init_signals(void);
175 extern void msvcrt_free_signals(void);
176
177 extern unsigned msvcrt_create_io_inherit_block(WORD*, BYTE**);
178
179 extern unsigned int __cdecl _control87(unsigned int, unsigned int);
180
181 /* run-time error codes */
182 #define _RT_STACK       0
183 #define _RT_NULLPTR     1
184 #define _RT_FLOAT       2
185 #define _RT_INTDIV      3
186 #define _RT_EXECMEM     5
187 #define _RT_EXECFORM    6
188 #define _RT_EXECENV     7
189 #define _RT_SPACEARG    8
190 #define _RT_SPACEENV    9
191 #define _RT_ABORT       10
192 #define _RT_NPTR        12
193 #define _RT_FPTR        13
194 #define _RT_BREAK       14
195 #define _RT_INT         15
196 #define _RT_THREAD      16
197 #define _RT_LOCK        17
198 #define _RT_HEAP        18
199 #define _RT_OPENCON     19
200 #define _RT_QWIN        20
201 #define _RT_NOMAIN      21
202 #define _RT_NONCONT     22
203 #define _RT_INVALDISP   23
204 #define _RT_ONEXIT      24
205 #define _RT_PUREVIRT    25
206 #define _RT_STDIOINIT   26
207 #define _RT_LOWIOINIT   27
208 #define _RT_HEAPINIT    28
209 #define _RT_DOMAIN      120
210 #define _RT_SING        121
211 #define _RT_TLOSS       122
212 #define _RT_CRNL        252
213 #define _RT_BANNER      255
214
215 struct MSVCRT___timeb32 {
216     MSVCRT___time32_t  time;
217     unsigned short millitm;
218     short          timezone;
219     short          dstflag;
220 };
221
222 struct MSVCRT___timeb64 {
223     MSVCRT___time64_t time;
224     unsigned short millitm;
225     short          timezone;
226     short          dstflag;
227 };
228
229 struct MSVCRT__iobuf {
230   char* _ptr;
231   int   _cnt;
232   char* _base;
233   int   _flag;
234   int   _file;
235   int   _charbuf;
236   int   _bufsiz;
237   char* _tmpfname;
238 };
239
240 typedef struct MSVCRT__iobuf MSVCRT_FILE;
241
242 struct MSVCRT_lconv {
243     char* decimal_point;
244     char* thousands_sep;
245     char* grouping;
246     char* int_curr_symbol;
247     char* currency_symbol;
248     char* mon_decimal_point;
249     char* mon_thousands_sep;
250     char* mon_grouping;
251     char* positive_sign;
252     char* negative_sign;
253     char int_frac_digits;
254     char frac_digits;
255     char p_cs_precedes;
256     char p_sep_by_space;
257     char n_cs_precedes;
258     char n_sep_by_space;
259     char p_sign_posn;
260     char n_sign_posn;
261 };
262
263 struct MSVCRT__exception {
264   int     type;
265   char*   name;
266   double  arg1;
267   double  arg2;
268   double  retval;
269 };
270
271 struct MSVCRT__complex {
272   double x;      /* Real part */
273   double y;      /* Imaginary part */
274 };
275
276 typedef struct MSVCRT__div_t {
277     int quot;  /* quotient */
278     int rem;   /* remainder */
279 } MSVCRT_div_t;
280
281 typedef struct MSVCRT__ldiv_t {
282     MSVCRT_long quot;  /* quotient */
283     MSVCRT_long rem;   /* remainder */
284 } MSVCRT_ldiv_t;
285
286 struct MSVCRT__heapinfo {
287   int*           _pentry;
288   MSVCRT_size_t  _size;
289   int            _useflag;
290 };
291
292 #ifdef __i386__
293 struct MSVCRT___JUMP_BUFFER {
294     unsigned long Ebp;
295     unsigned long Ebx;
296     unsigned long Edi;
297     unsigned long Esi;
298     unsigned long Esp;
299     unsigned long Eip;
300     unsigned long Registration;
301     unsigned long TryLevel;
302     /* Start of new struct members */
303     unsigned long Cookie;
304     unsigned long UnwindFunc;
305     unsigned long UnwindData[6];
306 };
307 #endif /* __i386__ */
308
309 struct MSVCRT__diskfree_t {
310   unsigned int total_clusters;
311   unsigned int avail_clusters;
312   unsigned int sectors_per_cluster;
313   unsigned int bytes_per_sector;
314 };
315
316 struct MSVCRT__finddata32_t {
317   unsigned int      attrib;
318   MSVCRT___time32_t time_create;
319   MSVCRT___time32_t time_access;
320   MSVCRT___time32_t time_write;
321   MSVCRT__fsize_t   size;
322   char              name[260];
323 };
324
325 struct MSVCRT__finddata32i64_t {
326   unsigned int      attrib;
327   MSVCRT___time32_t time_create;
328   MSVCRT___time32_t time_access;
329   MSVCRT___time32_t time_write;
330   __int64 DECLSPEC_ALIGN(8) size;
331   char              name[260];
332 };
333
334 struct MSVCRT__finddata64i32_t {
335   unsigned int      attrib;
336   MSVCRT___time64_t time_create;
337   MSVCRT___time64_t time_access;
338   MSVCRT___time64_t time_write;
339   MSVCRT__fsize_t   size;
340   char              name[260];
341 };
342
343 struct MSVCRT__finddata64_t {
344   unsigned int      attrib;
345   MSVCRT___time64_t time_create;
346   MSVCRT___time64_t time_access;
347   MSVCRT___time64_t time_write;
348   __int64 DECLSPEC_ALIGN(8) size;
349   char              name[260];
350 };
351
352 struct MSVCRT__wfinddata32_t {
353   unsigned int      attrib;
354   MSVCRT___time32_t time_create;
355   MSVCRT___time32_t time_access;
356   MSVCRT___time32_t time_write;
357   MSVCRT__fsize_t   size;
358   MSVCRT_wchar_t    name[260];
359 };
360
361 struct MSVCRT__wfinddata32i64_t {
362   unsigned int      attrib;
363   MSVCRT___time32_t time_create;
364   MSVCRT___time32_t time_access;
365   MSVCRT___time32_t time_write;
366   __int64 DECLSPEC_ALIGN(8) size;
367   MSVCRT_wchar_t    name[260];
368 };
369
370 struct MSVCRT__wfinddata64i32_t {
371   unsigned int      attrib;
372   MSVCRT___time64_t time_create;
373   MSVCRT___time64_t time_access;
374   MSVCRT___time64_t time_write;
375   MSVCRT__fsize_t   size;
376   MSVCRT_wchar_t    name[260];
377 };
378
379 struct MSVCRT__wfinddata64_t {
380   unsigned int      attrib;
381   MSVCRT___time64_t time_create;
382   MSVCRT___time64_t time_access;
383   MSVCRT___time64_t time_write;
384   __int64 DECLSPEC_ALIGN(8) size;
385   MSVCRT_wchar_t    name[260];
386 };
387
388 struct MSVCRT___utimbuf32
389 {
390     MSVCRT___time32_t actime;
391     MSVCRT___time32_t modtime;
392 };
393
394 struct MSVCRT___utimbuf64
395 {
396     MSVCRT___time64_t actime;
397     MSVCRT___time64_t modtime;
398 };
399
400 /* for FreeBSD */
401 #undef st_atime
402 #undef st_ctime
403 #undef st_mtime
404
405 struct MSVCRT__stat32 {
406   MSVCRT__dev_t     st_dev;
407   MSVCRT__ino_t     st_ino;
408   unsigned short    st_mode;
409   short             st_nlink;
410   short             st_uid;
411   short             st_gid;
412   MSVCRT__dev_t     st_rdev;
413   MSVCRT__off_t     st_size;
414   MSVCRT___time32_t st_atime;
415   MSVCRT___time32_t st_mtime;
416   MSVCRT___time32_t st_ctime;
417 };
418
419 struct MSVCRT__stat32i64 {
420   MSVCRT__dev_t     st_dev;
421   MSVCRT__ino_t     st_ino;
422   unsigned short    st_mode;
423   short             st_nlink;
424   short             st_uid;
425   short             st_gid;
426   MSVCRT__dev_t     st_rdev;
427   __int64 DECLSPEC_ALIGN(8) st_size;
428   MSVCRT___time32_t st_atime;
429   MSVCRT___time32_t st_mtime;
430   MSVCRT___time32_t st_ctime;
431 };
432
433 struct MSVCRT__stat64i32 {
434   MSVCRT__dev_t     st_dev;
435   MSVCRT__ino_t     st_ino;
436   unsigned short    st_mode;
437   short             st_nlink;
438   short             st_uid;
439   short             st_gid;
440   MSVCRT__dev_t     st_rdev;
441   MSVCRT__off_t     st_size;
442   MSVCRT___time64_t st_atime;
443   MSVCRT___time64_t st_mtime;
444   MSVCRT___time64_t st_ctime;
445 };
446
447 struct MSVCRT__stat64 {
448   MSVCRT__dev_t     st_dev;
449   MSVCRT__ino_t     st_ino;
450   unsigned short    st_mode;
451   short             st_nlink;
452   short             st_uid;
453   short             st_gid;
454   MSVCRT__dev_t     st_rdev;
455   __int64 DECLSPEC_ALIGN(8) st_size;
456   MSVCRT___time64_t st_atime;
457   MSVCRT___time64_t st_mtime;
458   MSVCRT___time64_t st_ctime;
459 };
460
461 #ifdef _WIN64
462 #define MSVCRT__finddata_t     MSVCRT__finddata64i32_t
463 #define MSVCRT__finddatai64_t  MSVCRT__finddata64_t
464 #define MSVCRT__wfinddata_t    MSVCRT__wfinddata64i32_t
465 #define MSVCRT__wfinddatai64_t MSVCRT__wfinddata64_t
466 #define MSVCRT__stat           MSVCRT__stat64i32
467 #define MSVCRT__stati64        MSVCRT__stat64
468 #else
469 #define MSVCRT__finddata_t     MSVCRT__finddata32_t
470 #define MSVCRT__finddatai64_t  MSVCRT__finddata32i64_t
471 #define MSVCRT__wfinddata_t    MSVCRT__wfinddata32_t
472 #define MSVCRT__wfinddatai64_t MSVCRT__wfinddata32i64_t
473 #define MSVCRT__stat           MSVCRT__stat32
474 #define MSVCRT__stati64        MSVCRT__stat32i64
475 #endif
476
477 #define MSVCRT_WEOF (MSVCRT_wint_t)(0xFFFF)
478 #define MSVCRT_EOF       (-1)
479 #define MSVCRT_TMP_MAX   0x7fff
480 #define MSVCRT_RAND_MAX  0x7fff
481 #define MSVCRT_BUFSIZ    512
482
483 #define MSVCRT_STDIN_FILENO  0
484 #define MSVCRT_STDOUT_FILENO 1
485 #define MSVCRT_STDERR_FILENO 2
486
487 /* more file._flag flags, but these conflict with Unix */
488 #define MSVCRT__IOFBF    0x0000
489 #define MSVCRT__IONBF    0x0004
490 #define MSVCRT__IOLBF    0x0040
491
492 #define MSVCRT_FILENAME_MAX 260
493 #define MSVCRT_DRIVE_MAX    3
494 #define MSVCRT_FNAME_MAX    256
495 #define MSVCRT_DIR_MAX      256
496 #define MSVCRT_EXT_MAX      256
497 #define MSVCRT_PATH_MAX     260
498 #define MSVCRT_stdin       (MSVCRT__iob+MSVCRT_STDIN_FILENO)
499 #define MSVCRT_stdout      (MSVCRT__iob+MSVCRT_STDOUT_FILENO)
500 #define MSVCRT_stderr      (MSVCRT__iob+MSVCRT_STDERR_FILENO)
501
502 #define MSVCRT__P_WAIT    0
503 #define MSVCRT__P_NOWAIT  1
504 #define MSVCRT__P_OVERLAY 2
505 #define MSVCRT__P_NOWAITO 3
506 #define MSVCRT__P_DETACH  4
507
508 #define MSVCRT_EPERM   1
509 #define MSVCRT_ENOENT  2
510 #define MSVCRT_ESRCH   3
511 #define MSVCRT_EINTR   4
512 #define MSVCRT_EIO     5
513 #define MSVCRT_ENXIO   6
514 #define MSVCRT_E2BIG   7
515 #define MSVCRT_ENOEXEC 8
516 #define MSVCRT_EBADF   9
517 #define MSVCRT_ECHILD  10
518 #define MSVCRT_EAGAIN  11
519 #define MSVCRT_ENOMEM  12
520 #define MSVCRT_EACCES  13
521 #define MSVCRT_EFAULT  14
522 #define MSVCRT_EBUSY   16
523 #define MSVCRT_EEXIST  17
524 #define MSVCRT_EXDEV   18
525 #define MSVCRT_ENODEV  19
526 #define MSVCRT_ENOTDIR 20
527 #define MSVCRT_EISDIR  21
528 #define MSVCRT_EINVAL  22
529 #define MSVCRT_ENFILE  23
530 #define MSVCRT_EMFILE  24
531 #define MSVCRT_ENOTTY  25
532 #define MSVCRT_EFBIG   27
533 #define MSVCRT_ENOSPC  28
534 #define MSVCRT_ESPIPE  29
535 #define MSVCRT_EROFS   30
536 #define MSVCRT_EMLINK  31
537 #define MSVCRT_EPIPE   32
538 #define MSVCRT_EDOM    33
539 #define MSVCRT_ERANGE  34
540 #define MSVCRT_EDEADLK 36
541 #define MSVCRT_EDEADLOCK MSVCRT_EDEADLK
542 #define MSVCRT_ENAMETOOLONG 38
543 #define MSVCRT_ENOLCK  39
544 #define MSVCRT_ENOSYS  40
545 #define MSVCRT_ENOTEMPTY 41
546 #define MSVCRT_EILSEQ    42
547 #define MSVCRT_STRUNCATE 80
548
549 #define MSVCRT_LC_ALL          0
550 #define MSVCRT_LC_COLLATE      1
551 #define MSVCRT_LC_CTYPE        2
552 #define MSVCRT_LC_MONETARY     3
553 #define MSVCRT_LC_NUMERIC      4
554 #define MSVCRT_LC_TIME         5
555 #define MSVCRT_LC_MIN          MSVCRT_LC_ALL
556 #define MSVCRT_LC_MAX          MSVCRT_LC_TIME
557
558 #define MSVCRT__HEAPEMPTY      -1
559 #define MSVCRT__HEAPOK         -2
560 #define MSVCRT__HEAPBADBEGIN   -3
561 #define MSVCRT__HEAPBADNODE    -4
562 #define MSVCRT__HEAPEND        -5
563 #define MSVCRT__HEAPBADPTR     -6
564
565 #define MSVCRT__FREEENTRY      0
566 #define MSVCRT__USEDENTRY      1
567
568 #define MSVCRT__OUT_TO_DEFAULT 0
569 #define MSVCRT__REPORT_ERRMODE 3
570
571 /* ASCII char classification table - binary compatible */
572 #define MSVCRT__UPPER    0x0001  /* C1_UPPER */
573 #define MSVCRT__LOWER    0x0002  /* C1_LOWER */
574 #define MSVCRT__DIGIT    0x0004  /* C1_DIGIT */
575 #define MSVCRT__SPACE    0x0008  /* C1_SPACE */
576 #define MSVCRT__PUNCT    0x0010  /* C1_PUNCT */
577 #define MSVCRT__CONTROL  0x0020  /* C1_CNTRL */
578 #define MSVCRT__BLANK    0x0040  /* C1_BLANK */
579 #define MSVCRT__HEX      0x0080  /* C1_XDIGIT */
580 #define MSVCRT__LEADBYTE 0x8000
581 #define MSVCRT__ALPHA   (0x0100|MSVCRT__UPPER|MSVCRT__LOWER)  /* (C1_ALPHA|_UPPER|_LOWER) */
582
583 #define MSVCRT__IOREAD   0x0001
584 #define MSVCRT__IOWRT    0x0002
585 #define MSVCRT__IOMYBUF  0x0008
586 #define MSVCRT__IOEOF    0x0010
587 #define MSVCRT__IOERR    0x0020
588 #define MSVCRT__IOSTRG   0x0040
589 #define MSVCRT__IORW     0x0080
590
591 #define MSVCRT__S_IEXEC  0x0040
592 #define MSVCRT__S_IWRITE 0x0080
593 #define MSVCRT__S_IREAD  0x0100
594 #define MSVCRT__S_IFIFO  0x1000
595 #define MSVCRT__S_IFCHR  0x2000
596 #define MSVCRT__S_IFDIR  0x4000
597 #define MSVCRT__S_IFREG  0x8000
598 #define MSVCRT__S_IFMT   0xF000
599
600 #define MSVCRT__LK_UNLCK  0
601 #define MSVCRT__LK_LOCK   1
602 #define MSVCRT__LK_NBLCK  2
603 #define MSVCRT__LK_RLCK   3
604 #define MSVCRT__LK_NBRLCK 4
605
606 #define MSVCRT__SH_COMPAT       0x00    /* Compatibility */
607 #define MSVCRT__SH_DENYRW       0x10    /* Deny read/write */
608 #define MSVCRT__SH_DENYWR       0x20    /* Deny write */
609 #define MSVCRT__SH_DENYRD       0x30    /* Deny read */
610 #define MSVCRT__SH_DENYNO       0x40    /* Deny nothing */
611
612 #define MSVCRT__O_RDONLY        0
613 #define MSVCRT__O_WRONLY        1
614 #define MSVCRT__O_RDWR          2
615 #define MSVCRT__O_ACCMODE       (MSVCRT__O_RDONLY|MSVCRT__O_WRONLY|MSVCRT__O_RDWR)
616 #define MSVCRT__O_APPEND        0x0008
617 #define MSVCRT__O_RANDOM        0x0010
618 #define MSVCRT__O_SEQUENTIAL    0x0020
619 #define MSVCRT__O_TEMPORARY     0x0040
620 #define MSVCRT__O_NOINHERIT     0x0080
621 #define MSVCRT__O_CREAT         0x0100
622 #define MSVCRT__O_TRUNC         0x0200
623 #define MSVCRT__O_EXCL          0x0400
624 #define MSVCRT__O_SHORT_LIVED   0x1000
625 #define MSVCRT__O_TEXT          0x4000
626 #define MSVCRT__O_BINARY        0x8000
627 #define MSVCRT__O_RAW           MSVCRT__O_BINARY
628
629 /* _statusfp bit flags */
630 #define MSVCRT__SW_INEXACT      0x00000001 /* inexact (precision) */
631 #define MSVCRT__SW_UNDERFLOW    0x00000002 /* underflow */
632 #define MSVCRT__SW_OVERFLOW     0x00000004 /* overflow */
633 #define MSVCRT__SW_ZERODIVIDE   0x00000008 /* zero divide */
634 #define MSVCRT__SW_INVALID      0x00000010 /* invalid */
635
636 #define MSVCRT__SW_UNEMULATED     0x00000040  /* unemulated instruction */
637 #define MSVCRT__SW_SQRTNEG        0x00000080  /* square root of a neg number */
638 #define MSVCRT__SW_STACKOVERFLOW  0x00000200  /* FP stack overflow */
639 #define MSVCRT__SW_STACKUNDERFLOW 0x00000400  /* FP stack underflow */
640
641 #define MSVCRT__SW_DENORMAL     0x00080000 /* denormal status bit */
642
643 /* fpclass constants */
644 #define MSVCRT__FPCLASS_SNAN 0x0001  /* Signaling "Not a Number" */
645 #define MSVCRT__FPCLASS_QNAN 0x0002  /* Quiet "Not a Number" */
646 #define MSVCRT__FPCLASS_NINF 0x0004  /* Negative Infinity */
647 #define MSVCRT__FPCLASS_NN   0x0008  /* Negative Normal */
648 #define MSVCRT__FPCLASS_ND   0x0010  /* Negative Denormal */
649 #define MSVCRT__FPCLASS_NZ   0x0020  /* Negative Zero */
650 #define MSVCRT__FPCLASS_PZ   0x0040  /* Positive Zero */
651 #define MSVCRT__FPCLASS_PD   0x0080  /* Positive Denormal */
652 #define MSVCRT__FPCLASS_PN   0x0100  /* Positive Normal */
653 #define MSVCRT__FPCLASS_PINF 0x0200  /* Positive Infinity */
654
655 #define MSVCRT__EM_INVALID    0x00000010
656 #define MSVCRT__EM_DENORMAL   0x00080000
657 #define MSVCRT__EM_ZERODIVIDE 0x00000008
658 #define MSVCRT__EM_OVERFLOW   0x00000004
659 #define MSVCRT__EM_UNDERFLOW  0x00000002
660 #define MSVCRT__EM_INEXACT    0x00000001
661 #define MSVCRT__IC_AFFINE     0x00040000
662 #define MSVCRT__IC_PROJECTIVE 0x00000000
663 #define MSVCRT__RC_CHOP       0x00000300
664 #define MSVCRT__RC_UP         0x00000200
665 #define MSVCRT__RC_DOWN       0x00000100
666 #define MSVCRT__RC_NEAR       0x00000000
667 #define MSVCRT__PC_24         0x00020000
668 #define MSVCRT__PC_53         0x00010000
669 #define MSVCRT__PC_64         0x00000000
670
671 #define MSVCRT_CLOCKS_PER_SEC 1000
672
673 /* signals */
674 #define MSVCRT_SIGINT   2
675 #define MSVCRT_SIGILL   4
676 #define MSVCRT_SIGFPE   8
677 #define MSVCRT_SIGSEGV  11
678 #define MSVCRT_SIGTERM  15
679 #define MSVCRT_SIGBREAK 21
680 #define MSVCRT_SIGABRT  22
681 #define MSVCRT_NSIG     (MSVCRT_SIGABRT + 1)
682
683 typedef void (__cdecl *MSVCRT___sighandler_t)(int);
684
685 #define MSVCRT_SIG_DFL ((MSVCRT___sighandler_t)0)
686 #define MSVCRT_SIG_IGN ((MSVCRT___sighandler_t)1)
687 #define MSVCRT_SIG_ERR ((MSVCRT___sighandler_t)-1)
688
689 #define MSVCRT__FPE_INVALID            0x81
690 #define MSVCRT__FPE_DENORMAL           0x82
691 #define MSVCRT__FPE_ZERODIVIDE         0x83
692 #define MSVCRT__FPE_OVERFLOW           0x84
693 #define MSVCRT__FPE_UNDERFLOW          0x85
694 #define MSVCRT__FPE_INEXACT            0x86
695 #define MSVCRT__FPE_UNEMULATED         0x87
696 #define MSVCRT__FPE_SQRTNEG            0x88
697 #define MSVCRT__FPE_STACKOVERFLOW      0x8a
698 #define MSVCRT__FPE_STACKUNDERFLOW     0x8b
699 #define MSVCRT__FPE_EXPLICITGEN        0x8c
700
701 #define _MS     0x01
702 #define _MP     0x02
703 #define _M1     0x04
704 #define _M2     0x08
705
706 #define _SBUP   0x10
707 #define _SBLOW  0x20
708
709 #define _MBC_SINGLE     0
710 #define _MBC_LEAD       1
711 #define _MBC_TRAIL      2
712 #define _MBC_ILLEGAL    -1
713
714 #define _MB_CP_SBCS     0
715 #define _MB_CP_OEM      -2
716 #define _MB_CP_ANSI     -3
717 #define _MB_CP_LOCALE   -4
718
719 #define MSVCRT__TRUNCATE ((MSVCRT_size_t)-1)
720
721 #define _MAX__TIME64_T    (((MSVCRT___time64_t)0x00000007 << 32) | 0x93406FFF)
722
723 void  __cdecl    MSVCRT_free(void*);
724 void* __cdecl    MSVCRT_malloc(MSVCRT_size_t);
725 void* __cdecl    MSVCRT_calloc(MSVCRT_size_t,MSVCRT_size_t);
726 void* __cdecl    MSVCRT_realloc(void*,MSVCRT_size_t);
727
728 int __cdecl      MSVCRT_iswalpha(MSVCRT_wint_t);
729 int __cdecl      MSVCRT_iswspace(MSVCRT_wint_t);
730 int __cdecl      MSVCRT_iswdigit(MSVCRT_wint_t);
731 int __cdecl      MSVCRT_isleadbyte(int);
732
733 int __cdecl      MSVCRT_fgetc(MSVCRT_FILE*);
734 int __cdecl      MSVCRT_ungetc(int,MSVCRT_FILE*);
735 MSVCRT_wint_t __cdecl MSVCRT_fgetwc(MSVCRT_FILE*);
736 MSVCRT_wint_t __cdecl MSVCRT_ungetwc(MSVCRT_wint_t,MSVCRT_FILE*);
737 void __cdecl     MSVCRT__exit(int);
738 void __cdecl     MSVCRT_abort(void);
739 MSVCRT_ulong* __cdecl MSVCRT___doserrno(void);
740 int* __cdecl     MSVCRT__errno(void);
741 char* __cdecl    MSVCRT_getenv(const char*);
742 char* __cdecl    MSVCRT_setlocale(int,const char*);
743 int __cdecl      MSVCRT_fclose(MSVCRT_FILE*);
744 void __cdecl     MSVCRT_terminate(void);
745 MSVCRT_FILE* __cdecl MSVCRT__iob_func(void);
746 MSVCRT_clock_t __cdecl MSVCRT_clock(void);
747 MSVCRT___time32_t __cdecl MSVCRT__time32(MSVCRT___time32_t*);
748 MSVCRT___time64_t __cdecl MSVCRT__time64(MSVCRT___time64_t*);
749 MSVCRT_FILE*   __cdecl MSVCRT__fdopen(int, const char *);
750 MSVCRT_FILE*   __cdecl MSVCRT__wfdopen(int, const MSVCRT_wchar_t *);
751 int            __cdecl MSVCRT_vsnprintf(char *str, MSVCRT_size_t len, const char *format, __ms_va_list valist);
752 int            __cdecl MSVCRT_vsnwprintf(MSVCRT_wchar_t *str, MSVCRT_size_t len,
753                                        const MSVCRT_wchar_t *format, __ms_va_list valist );
754 int            __cdecl MSVCRT_sprintf(char*,const char*,...);
755 int            __cdecl MSVCRT__scprintf(const char*,...);
756 int            __cdecl MSVCRT_raise(int sig);
757
758 typedef struct MSVCRT_tagLC_ID {
759     unsigned short wLanguage;
760     unsigned short wCountry;
761     unsigned short wCodePage;
762 } MSVCRT_LC_ID, *MSVCRT_LPLC_ID;
763
764 typedef struct MSVCRT_threadlocaleinfostruct {
765     int refcount;
766     unsigned int lc_codepage;
767     unsigned int lc_collate_cp;
768     unsigned long lc_handle[6];
769     MSVCRT_LC_ID lc_id[6];
770     struct {
771         char *locale;
772         wchar_t *wlocale;
773         int *refcount;
774         int *wrefcount;
775     } lc_category[6];
776     int lc_clike;
777     int mb_cur_max;
778     int *lconv_intl_refcount;
779     int *lconv_num_refcount;
780     int *lconv_mon_refcount;
781     struct MSVCRT_lconv *lconv;
782     int *ctype1_refcount;
783     unsigned short *ctype1;
784     unsigned short *pctype;
785     unsigned char *pclmap;
786     unsigned char *pcumap;
787     struct MSVCRT___lc_time_data *lc_time_curr;
788 } MSVCRT_threadlocinfo;
789
790 typedef struct MSVCRT_threadmbcinfostruct {
791     int refcount;
792     int mbcodepage;
793     int ismbcodepage;
794     int mblcid;
795     unsigned short mbulinfo[6];
796     char mbctype[257];
797     char mbcasemap[256];
798 } MSVCRT_threadmbcinfo;
799
800 typedef struct MSVCRT_threadlocaleinfostruct *MSVCRT_pthreadlocinfo;
801 typedef struct MSVCRT_threadmbcinfostruct *MSVCRT_pthreadmbcinfo;
802
803 typedef struct MSVCRT_localeinfo_struct
804 {
805     MSVCRT_pthreadlocinfo locinfo;
806     MSVCRT_pthreadmbcinfo mbcinfo;
807 } MSVCRT__locale_tstruct, *MSVCRT__locale_t;
808
809 #define MSVCRT__ENABLE_PER_THREAD_LOCALE 1
810 #define MSVCRT__DISABLE_PER_THREAD_LOCALE 2
811
812 extern MSVCRT__locale_t MSVCRT_locale;
813 MSVCRT__locale_t get_locale(void);
814 void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
815
816 #ifndef __WINE_MSVCRT_TEST
817 int            __cdecl MSVCRT__write(int,const void*,unsigned int);
818 int            __cdecl _getch(void);
819 int            __cdecl _ismbblead(unsigned int);
820 int            __cdecl _ismbstrail(const unsigned char* start, const unsigned char* str);
821 MSVCRT_intptr_t __cdecl MSVCRT__spawnve(int,const char*,const char* const *,const char* const *);
822 MSVCRT_intptr_t __cdecl MSVRT__spawnvpe(int,const char*,const char* const *,const char* const *);
823 MSVCRT_intptr_t __cdecl _wspawnve(int,const MSVCRT_wchar_t*,const MSVCRT_wchar_t* const *,const MSVCRT_wchar_t* const *);
824 MSVCRT_intptr_t __cdecl _wspawnvpe(int,const MSVCRT_wchar_t*,const MSVCRT_wchar_t* const *,const MSVCRT_wchar_t* const *);
825 void __cdecl     _searchenv(const char*,const char*,char*);
826 int __cdecl      _getdrive(void);
827 char* __cdecl    _strdup(const char*);
828 char* __cdecl    MSVCRT__strnset(char*,int,MSVCRT_size_t);
829 char* __cdecl    _strset(char*,int);
830 int __cdecl      _ungetch(int);
831 int __cdecl      _cputs(const char*);
832 int __cdecl      _cprintf(const char*,...);
833 char*** __cdecl  __p__environ(void);
834 int*    __cdecl  __p___mb_cur_max(void);
835 unsigned int*  __cdecl __p__fmode(void);
836 MSVCRT_wchar_t* __cdecl _wcsdup(const MSVCRT_wchar_t*);
837 MSVCRT_wchar_t*** __cdecl __p__wenviron(void);
838 char*   __cdecl _strdate(char* date);
839 char*   __cdecl _strtime(char* date);
840 int     __cdecl _setmbcp(int);
841 int     __cdecl MSVCRT__close(int);
842 int     __cdecl MSVCRT__dup(int);
843 int     __cdecl MSVCRT__dup2(int, int);
844 int     __cdecl MSVCRT__pipe(int *, unsigned int, int);
845 MSVCRT_wchar_t* __cdecl _wgetenv(const MSVCRT_wchar_t*);
846 void __cdecl    _wsearchenv(const MSVCRT_wchar_t*, const MSVCRT_wchar_t*, MSVCRT_wchar_t*);
847 MSVCRT_intptr_t __cdecl MSVCRT__spawnvpe(int, const char*, const char* const*, const char* const*);
848 void __cdecl MSVCRT__invalid_parameter(const MSVCRT_wchar_t *expr, const MSVCRT_wchar_t *func,
849                                        const MSVCRT_wchar_t *file, unsigned int line, MSVCRT_uintptr_t arg);
850
851 /* Maybe one day we'll enable the invalid parameter handlers with the full set of information (msvcrXXd)
852  *      #define MSVCRT_INVALID_PMT(x) MSVCRT_call_invalid_parameter_handler(x, __FUNCTION__, __FILE__, __LINE__, 0)
853  *      #define MSVCRT_CHECK_PMT(x)   ((x) ? TRUE : MSVCRT_INVALID_PMT(#x),FALSE)
854  * Until this is done, just keep the same semantics for CHECK_PMT(), but without generating / sending
855  * any information
856  * NB : MSVCRT_call_invalid_parameter_handler is a wrapper around MSVCRT__invalid_parameter in order
857  * to do the Ansi to Unicode transformation
858  */
859 #define MSVCRT_INVALID_PMT(x) MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0)
860 #define MSVCRT_CHECK_PMT(x)   ((x) || (MSVCRT_INVALID_PMT(0),FALSE))
861 #endif
862
863 #endif /* __WINE_MSVCRT_H */