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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - Symbols are prefixed with MSVCRT_ if they conflict
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.
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!
36 #ifndef __WINE_MSVCRT_H
37 #define __WINE_MSVCRT_H
48 typedef unsigned short MSVCRT_wchar_t;
49 typedef unsigned short MSVCRT_wint_t;
50 typedef unsigned short MSVCRT_wctype_t;
51 typedef unsigned short MSVCRT__ino_t;
52 typedef unsigned long MSVCRT__fsize_t;
53 typedef unsigned int MSVCRT_size_t;
54 typedef unsigned int MSVCRT__dev_t;
55 typedef int MSVCRT__off_t;
56 typedef long MSVCRT_clock_t;
57 typedef long MSVCRT_time_t;
58 typedef __int64 MSVCRT_fpos_t;
60 typedef void (*MSVCRT_terminate_handler)();
61 typedef void (*MSVCRT_terminate_function)();
62 typedef void (*MSVCRT_unexpected_handler)();
63 typedef void (*MSVCRT_unexpected_function)();
64 typedef void (*MSVCRT__se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
65 typedef void (*MSVCRT__beginthread_start_routine_t)(void *);
66 typedef unsigned int (__stdcall *MSVCRT__beginthreadex_start_routine_t)(void *);
67 typedef int (*MSVCRT__onexit_t)(void);
71 extern DWORD msvcrt_tls_index;
73 struct __thread_data {
75 unsigned long thread_doserrno;
76 char *mbstok_next; /* next ptr for mbstok() */
77 char *efcvt_buffer; /* buffer for ecvt/fcvt */
79 MSVCRT_terminate_function terminate_handler;
80 MSVCRT_unexpected_function unexpected_handler;
81 MSVCRT__se_translator_function se_translator;
82 EXCEPTION_RECORD *exc_record;
85 typedef struct __thread_data thread_data_t;
87 extern thread_data_t *msvcrt_get_thread_data(void);
89 extern int msvcrt_current_lc_all_cp;
91 void msvcrt_set_errno(int);
92 char* msvcrt_strndup(const char*,unsigned int);
93 MSVCRT_wchar_t *msvcrt_wstrndup(const MSVCRT_wchar_t*, unsigned int);
96 void _amsg_exit(int errnum);
98 extern char **_environ;
99 extern MSVCRT_wchar_t **_wenviron;
101 extern char ** msvcrt_SnapshotOfEnvironmentA(char **);
102 extern MSVCRT_wchar_t ** msvcrt_SnapshotOfEnvironmentW(MSVCRT_wchar_t **);
104 /* FIXME: This should be declared in new.h but it's not an extern "C" so
105 * it would not be much use anyway. Even for Winelib applications.
107 int MSVCRT__set_new_mode(int mode);
109 void* MSVCRT_operator_new(unsigned long size);
110 void MSVCRT_operator_delete(void*);
112 typedef void* (*malloc_func_t)(MSVCRT_size_t);
113 typedef void (*free_func_t)(void*);
115 extern char* __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
116 extern char* __unDNameEx(char *,const char*,int,malloc_func_t,free_func_t,void *,unsigned short int);
118 /* Setup and teardown multi threaded locks */
119 extern void msvcrt_init_mt_locks(void);
120 extern void msvcrt_free_mt_locks(void);
122 extern void msvcrt_init_io(void);
123 extern void msvcrt_free_io(void);
124 extern void msvcrt_init_console(void);
125 extern void msvcrt_free_console(void);
126 extern void msvcrt_init_args(void);
127 extern void msvcrt_free_args(void);
128 extern void msvcrt_init_signals(void);
129 extern void msvcrt_free_signals(void);
131 extern unsigned msvcrt_create_io_inherit_block(STARTUPINFOA*);
133 /* run-time error codes */
135 #define _RT_NULLPTR 1
138 #define _RT_EXECMEM 5
139 #define _RT_EXECFORM 6
140 #define _RT_EXECENV 7
141 #define _RT_SPACEARG 8
142 #define _RT_SPACEENV 9
148 #define _RT_THREAD 16
151 #define _RT_OPENCON 19
153 #define _RT_NOMAIN 21
154 #define _RT_NONCONT 22
155 #define _RT_INVALDISP 23
156 #define _RT_ONEXIT 24
157 #define _RT_PUREVIRT 25
158 #define _RT_STDIOINIT 26
159 #define _RT_LOWIOINIT 27
160 #define _RT_HEAPINIT 28
161 #define _RT_DOMAIN 120
163 #define _RT_TLOSS 122
165 #define _RT_BANNER 255
179 struct MSVCRT__timeb {
181 unsigned short millitm;
186 struct MSVCRT__iobuf {
197 typedef struct MSVCRT__iobuf MSVCRT_FILE;
199 struct MSVCRT_lconv {
203 char* int_curr_symbol;
204 char* currency_symbol;
205 char* mon_decimal_point;
206 char* mon_thousands_sep;
210 char int_frac_digits;
220 struct MSVCRT__exception {
228 struct MSVCRT__complex {
229 double x; /* Real part */
230 double y; /* Imaginary part */
233 typedef struct MSVCRT__div_t {
234 int quot; /* quotient */
235 int rem; /* remainder */
238 typedef struct MSVCRT__ldiv_t {
239 long quot; /* quotient */
240 long rem; /* remainder */
243 struct MSVCRT__heapinfo {
250 struct MSVCRT___JUMP_BUFFER {
257 unsigned long Registration;
258 unsigned long TryLevel;
259 /* Start of new struct members */
260 unsigned long Cookie;
261 unsigned long UnwindFunc;
262 unsigned long UnwindData[6];
264 #endif /* __i386__ */
266 struct MSVCRT__diskfree_t {
267 unsigned int total_clusters;
268 unsigned int avail_clusters;
269 unsigned int sectors_per_cluster;
270 unsigned int bytes_per_sector;
273 struct MSVCRT__finddata_t {
275 MSVCRT_time_t time_create;
276 MSVCRT_time_t time_access;
277 MSVCRT_time_t time_write;
278 MSVCRT__fsize_t size;
282 struct MSVCRT__finddatai64_t {
284 MSVCRT_time_t time_create;
285 MSVCRT_time_t time_access;
286 MSVCRT_time_t time_write;
291 struct MSVCRT__wfinddata_t {
293 MSVCRT_time_t time_create;
294 MSVCRT_time_t time_access;
295 MSVCRT_time_t time_write;
296 MSVCRT__fsize_t size;
297 MSVCRT_wchar_t name[260];
300 struct MSVCRT__wfinddatai64_t {
302 MSVCRT_time_t time_create;
303 MSVCRT_time_t time_access;
304 MSVCRT_time_t time_write;
306 MSVCRT_wchar_t name[260];
309 struct MSVCRT__utimbuf
311 MSVCRT_time_t actime;
312 MSVCRT_time_t modtime;
320 struct MSVCRT__stat {
321 MSVCRT__dev_t st_dev;
322 MSVCRT__ino_t st_ino;
323 unsigned short st_mode;
327 MSVCRT__dev_t st_rdev;
328 MSVCRT__off_t st_size;
329 MSVCRT_time_t st_atime;
330 MSVCRT_time_t st_mtime;
331 MSVCRT_time_t st_ctime;
335 MSVCRT__dev_t st_dev;
336 MSVCRT__ino_t st_ino;
337 unsigned short st_mode;
341 MSVCRT__dev_t st_rdev;
342 MSVCRT__off_t st_size;
343 MSVCRT_time_t st_atime;
344 MSVCRT_time_t st_mtime;
345 MSVCRT_time_t st_ctime;
348 struct MSVCRT__stati64 {
349 MSVCRT__dev_t st_dev;
350 MSVCRT__ino_t st_ino;
351 unsigned short st_mode;
355 MSVCRT__dev_t st_rdev;
357 MSVCRT_time_t st_atime;
358 MSVCRT_time_t st_mtime;
359 MSVCRT_time_t st_ctime;
362 #define MSVCRT_WEOF (MSVCRT_wint_t)(0xFFFF)
363 #define MSVCRT_EOF (-1)
364 #define MSVCRT_TMP_MAX 0x7fff
365 #define MSVCRT_BUFSIZ 512
367 #define MSVCRT_STDIN_FILENO 0
368 #define MSVCRT_STDOUT_FILENO 1
369 #define MSVCRT_STDERR_FILENO 2
371 /* more file._flag flags, but these conflict with Unix */
372 #define MSVCRT__IOFBF 0x0000
373 #define MSVCRT__IONBF 0x0004
374 #define MSVCRT__IOLBF 0x0040
376 #define MSVCRT_FILENAME_MAX 260
377 #define MSVCRT_stdin (MSVCRT__iob+MSVCRT_STDIN_FILENO)
378 #define MSVCRT_stdout (MSVCRT__iob+MSVCRT_STDOUT_FILENO)
379 #define MSVCRT_stderr (MSVCRT__iob+MSVCRT_STDERR_FILENO)
381 #define MSVCRT__P_WAIT 0
382 #define MSVCRT__P_NOWAIT 1
383 #define MSVCRT__P_OVERLAY 2
384 #define MSVCRT__P_NOWAITO 3
385 #define MSVCRT__P_DETACH 4
387 #define MSVCRT_EPERM 1
388 #define MSVCRT_ENOENT 2
389 #define MSVCRT_ESRCH 3
390 #define MSVCRT_EINTR 4
392 #define MSVCRT_ENXIO 6
393 #define MSVCRT_E2BIG 7
394 #define MSVCRT_ENOEXEC 8
395 #define MSVCRT_EBADF 9
396 #define MSVCRT_ECHILD 10
397 #define MSVCRT_EAGAIN 11
398 #define MSVCRT_ENOMEM 12
399 #define MSVCRT_EACCES 13
400 #define MSVCRT_EFAULT 14
401 #define MSVCRT_EBUSY 16
402 #define MSVCRT_EEXIST 17
403 #define MSVCRT_EXDEV 18
404 #define MSVCRT_ENODEV 19
405 #define MSVCRT_ENOTDIR 20
406 #define MSVCRT_EISDIR 21
407 #define MSVCRT_EINVAL 22
408 #define MSVCRT_ENFILE 23
409 #define MSVCRT_EMFILE 24
410 #define MSVCRT_ENOTTY 25
411 #define MSVCRT_EFBIG 27
412 #define MSVCRT_ENOSPC 28
413 #define MSVCRT_ESPIPE 29
414 #define MSVCRT_EROFS 30
415 #define MSVCRT_EMLINK 31
416 #define MSVCRT_EPIPE 32
417 #define MSVCRT_EDOM 33
418 #define MSVCRT_ERANGE 34
419 #define MSVCRT_EDEADLK 36
420 #define MSVCRT_EDEADLOCK MSVCRT_EDEADLK
421 #define MSVCRT_ENAMETOOLONG 38
422 #define MSVCRT_ENOLCK 39
423 #define MSVCRT_ENOSYS 40
424 #define MSVCRT_ENOTEMPTY 41
426 #define MSVCRT_LC_ALL 0
427 #define MSVCRT_LC_COLLATE 1
428 #define MSVCRT_LC_CTYPE 2
429 #define MSVCRT_LC_MONETARY 3
430 #define MSVCRT_LC_NUMERIC 4
431 #define MSVCRT_LC_TIME 5
432 #define MSVCRT_LC_MIN MSVCRT_LC_ALL
433 #define MSVCRT_LC_MAX MSVCRT_LC_TIME
435 #define MSVCRT__HEAPEMPTY -1
436 #define MSVCRT__HEAPOK -2
437 #define MSVCRT__HEAPBADBEGIN -3
438 #define MSVCRT__HEAPBADNODE -4
439 #define MSVCRT__HEAPEND -5
440 #define MSVCRT__HEAPBADPTR -6
442 #define MSVCRT__FREEENTRY 0
443 #define MSVCRT__USEDENTRY 1
445 #define MSVCRT__OUT_TO_DEFAULT 0
446 #define MSVCRT__REPORT_ERRMODE 3
448 /* ASCII char classification table - binary compatible */
449 #define MSVCRT__UPPER 0x0001 /* C1_UPPER */
450 #define MSVCRT__LOWER 0x0002 /* C1_LOWER */
451 #define MSVCRT__DIGIT 0x0004 /* C1_DIGIT */
452 #define MSVCRT__SPACE 0x0008 /* C1_SPACE */
453 #define MSVCRT__PUNCT 0x0010 /* C1_PUNCT */
454 #define MSVCRT__CONTROL 0x0020 /* C1_CNTRL */
455 #define MSVCRT__BLANK 0x0040 /* C1_BLANK */
456 #define MSVCRT__HEX 0x0080 /* C1_XDIGIT */
457 #define MSVCRT__LEADBYTE 0x8000
458 #define MSVCRT__ALPHA (0x0100|MSVCRT__UPPER|MSVCRT__LOWER) /* (C1_ALPHA|_UPPER|_LOWER) */
460 #define MSVCRT__IOREAD 0x0001
461 #define MSVCRT__IOWRT 0x0002
462 #define MSVCRT__IOMYBUF 0x0008
463 #define MSVCRT__IOEOF 0x0010
464 #define MSVCRT__IOERR 0x0020
465 #define MSVCRT__IOSTRG 0x0040
466 #define MSVCRT__IORW 0x0080
468 #define MSVCRT__S_IEXEC 0x0040
469 #define MSVCRT__S_IWRITE 0x0080
470 #define MSVCRT__S_IREAD 0x0100
471 #define MSVCRT__S_IFIFO 0x1000
472 #define MSVCRT__S_IFCHR 0x2000
473 #define MSVCRT__S_IFDIR 0x4000
474 #define MSVCRT__S_IFREG 0x8000
475 #define MSVCRT__S_IFMT 0xF000
477 #define MSVCRT__LK_UNLCK 0
478 #define MSVCRT__LK_LOCK 1
479 #define MSVCRT__LK_NBLCK 2
480 #define MSVCRT__LK_RLCK 3
481 #define MSVCRT__LK_NBRLCK 4
483 #define MSVCRT__SH_COMPAT 0x00 /* Compatibility */
484 #define MSVCRT__SH_DENYRW 0x10 /* Deny read/write */
485 #define MSVCRT__SH_DENYWR 0x20 /* Deny write */
486 #define MSVCRT__SH_DENYRD 0x30 /* Deny read */
487 #define MSVCRT__SH_DENYNO 0x40 /* Deny nothing */
489 #define MSVCRT__O_RDONLY 0
490 #define MSVCRT__O_WRONLY 1
491 #define MSVCRT__O_RDWR 2
492 #define MSVCRT__O_ACCMODE (MSVCRT__O_RDONLY|MSVCRT__O_WRONLY|MSVCRT__O_RDWR)
493 #define MSVCRT__O_APPEND 0x0008
494 #define MSVCRT__O_RANDOM 0x0010
495 #define MSVCRT__O_SEQUENTIAL 0x0020
496 #define MSVCRT__O_TEMPORARY 0x0040
497 #define MSVCRT__O_NOINHERIT 0x0080
498 #define MSVCRT__O_CREAT 0x0100
499 #define MSVCRT__O_TRUNC 0x0200
500 #define MSVCRT__O_EXCL 0x0400
501 #define MSVCRT__O_SHORT_LIVED 0x1000
502 #define MSVCRT__O_TEXT 0x4000
503 #define MSVCRT__O_BINARY 0x8000
504 #define MSVCRT__O_RAW MSVCRT__O_BINARY
506 /* _statusfp bit flags */
507 #define MSVCRT__SW_INEXACT 0x00000001 /* inexact (precision) */
508 #define MSVCRT__SW_UNDERFLOW 0x00000002 /* underflow */
509 #define MSVCRT__SW_OVERFLOW 0x00000004 /* overflow */
510 #define MSVCRT__SW_ZERODIVIDE 0x00000008 /* zero divide */
511 #define MSVCRT__SW_INVALID 0x00000010 /* invalid */
513 #define MSVCRT__SW_UNEMULATED 0x00000040 /* unemulated instruction */
514 #define MSVCRT__SW_SQRTNEG 0x00000080 /* square root of a neg number */
515 #define MSVCRT__SW_STACKOVERFLOW 0x00000200 /* FP stack overflow */
516 #define MSVCRT__SW_STACKUNDERFLOW 0x00000400 /* FP stack underflow */
518 #define MSVCRT__SW_DENORMAL 0x00080000 /* denormal status bit */
520 /* fpclass constants */
521 #define MSVCRT__FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
522 #define MSVCRT__FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
523 #define MSVCRT__FPCLASS_NINF 0x0004 /* Negative Infinity */
524 #define MSVCRT__FPCLASS_NN 0x0008 /* Negative Normal */
525 #define MSVCRT__FPCLASS_ND 0x0010 /* Negative Denormal */
526 #define MSVCRT__FPCLASS_NZ 0x0020 /* Negative Zero */
527 #define MSVCRT__FPCLASS_PZ 0x0040 /* Positive Zero */
528 #define MSVCRT__FPCLASS_PD 0x0080 /* Positive Denormal */
529 #define MSVCRT__FPCLASS_PN 0x0100 /* Positive Normal */
530 #define MSVCRT__FPCLASS_PINF 0x0200 /* Positive Infinity */
532 #define MSVCRT__EM_INVALID 0x00000010
533 #define MSVCRT__EM_DENORMAL 0x00080000
534 #define MSVCRT__EM_ZERODIVIDE 0x00000008
535 #define MSVCRT__EM_OVERFLOW 0x00000004
536 #define MSVCRT__EM_UNDERFLOW 0x00000002
537 #define MSVCRT__EM_INEXACT 0x00000001
538 #define MSVCRT__IC_AFFINE 0x00040000
539 #define MSVCRT__IC_PROJECTIVE 0x00000000
540 #define MSVCRT__RC_CHOP 0x00000300
541 #define MSVCRT__RC_UP 0x00000200
542 #define MSVCRT__RC_DOWN 0x00000100
543 #define MSVCRT__RC_NEAR 0x00000000
544 #define MSVCRT__PC_24 0x00020000
545 #define MSVCRT__PC_53 0x00010000
546 #define MSVCRT__PC_64 0x00000000
548 #define MSVCRT_CLOCKS_PER_SEC 1000
550 void MSVCRT_free(void*);
551 void* MSVCRT_malloc(MSVCRT_size_t);
552 void* MSVCRT_calloc(MSVCRT_size_t,MSVCRT_size_t);
553 void* MSVCRT_realloc(void*,MSVCRT_size_t);
555 int MSVCRT_iswalpha(MSVCRT_wint_t);
556 int MSVCRT_iswspace(MSVCRT_wint_t);
557 int MSVCRT_iswdigit(MSVCRT_wint_t);
558 int MSVCRT_isleadbyte(int);
560 int MSVCRT_fgetc(MSVCRT_FILE*);
561 int MSVCRT_ungetc(int,MSVCRT_FILE*);
562 MSVCRT_wint_t MSVCRT_fgetwc(MSVCRT_FILE*);
563 MSVCRT_wint_t MSVCRT_ungetwc(MSVCRT_wint_t,MSVCRT_FILE*);
564 void MSVCRT__exit(int);
565 void MSVCRT_abort(void);
566 unsigned long* MSVCRT___doserrno(void);
567 int* MSVCRT__errno(void);
568 char* MSVCRT_getenv(const char*);
569 char* MSVCRT_setlocale(int,const char*);
570 int MSVCRT_fclose(MSVCRT_FILE*);
571 void MSVCRT_terminate(void);
572 MSVCRT_FILE* MSVCRT__p__iob(void);
573 MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t);
574 struct MSVCRT_tm* MSVCRT_localtime(const MSVCRT_time_t* secs);
575 struct MSVCRT_tm* MSVCRT_gmtime(const MSVCRT_time_t* secs);
576 MSVCRT_clock_t MSVCRT_clock(void);
577 double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2);
578 MSVCRT_time_t MSVCRT_time(MSVCRT_time_t*);
579 MSVCRT_FILE* MSVCRT__fdopen(int, const char *);
580 int MSVCRT_vsnprintf(char *str, unsigned int len, const char *format, va_list valist);
582 #ifndef __WINE_MSVCRT_TEST
583 int _write(int,const void*,unsigned int);
585 int _vsnwprintf(MSVCRT_wchar_t*,MSVCRT_size_t,const MSVCRT_wchar_t*,va_list);
586 int _ismbstrail(const unsigned char* start, const unsigned char* str);
587 int _spawnve(int,const char*,const char* const *,const char* const *);
588 void _searchenv(const char*,const char*,char*);
590 char* _strdup(const char*);
591 char* _strnset(char*,int,MSVCRT_size_t);
592 char* _strset(char*,int);
594 int _cputs(const char*);
595 int _cprintf(const char*,...);
596 int _snprintf(char*,size_t,const char*,...);
597 char*** __p__environ(void);
598 int* __p___mb_cur_max(void);
599 unsigned int* __p__fmode(void);
600 MSVCRT_wchar_t* _wcsdup(const MSVCRT_wchar_t*);
601 MSVCRT_wchar_t*** __p__wenviron(void);
602 char* _strdate(char* date);
603 char* _strtime(char* date);
604 void _ftime(struct MSVCRT__timeb *buf);
608 int _pipe(int *, unsigned int, int);
611 /* FIXME: Functions that we forward to. They shouldn't be defined
612 * here, but for now they're not declared in the standard headers.
614 void _splitpath(const char*,char*,char*,char*,char*);
615 char* _strlwr(char*);
616 char* _strupr(char*);
618 #endif /* __WINE_MSVCRT_H */