Add C99 compiliant iso646.h header
[tinycc.git] / win32 / lib / crt1.c
blob0e04fc012ba38dad062bddf400f603967d43154d
1 // =============================================
2 // crt1.c
4 // _UNICODE for tchar.h, UNICODE for API
5 #include <tchar.h>
7 #include <stdio.h>
8 #include <stdlib.h>
10 #define _UNKNOWN_APP 0
11 #define _CONSOLE_APP 1
12 #define _GUI_APP 2
14 #define _MCW_PC 0x00030000 // Precision Control
15 #define _PC_24 0x00020000 // 24 bits
16 #define _PC_53 0x00010000 // 53 bits
17 #define _PC_64 0x00000000 // 64 bits
19 #ifdef _UNICODE
20 #define __tgetmainargs __wgetmainargs
21 #define _tstart _wstart
22 #define _tmain wmain
23 #define _runtmain _runwmain
24 #else
25 #define __tgetmainargs __getmainargs
26 #define _tstart _start
27 #define _tmain main
28 #define _runtmain _runmain
29 #endif
31 typedef struct { int newmode; } _startupinfo;
32 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
33 void __cdecl __set_app_type(int apptype);
34 unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
35 extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
37 /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
38 int _dowildcard;
40 void _tstart(void)
42 __TRY__
43 _startupinfo start_info = {0};
45 // Sets the current application type
46 __set_app_type(_CONSOLE_APP);
48 // Set default FP precision to 53 bits (8-byte double)
49 // _MCW_PC (Precision control) is not supported on ARM
50 #if defined __i386__ || defined __x86_64__
51 _controlfp(_PC_53, _MCW_PC);
52 #endif
54 __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
55 exit(_tmain(__argc, __targv, _tenviron));
58 int _runtmain(int argc, /* as tcc passed in */ char **argv)
60 #ifdef UNICODE
61 _startupinfo start_info = {0};
63 __tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info);
64 /* may be wrong when tcc has received wildcards (*.c) */
65 if (argc < __argc) {
66 __targv += __argc - argc;
67 __argc = argc;
69 #else
70 __argc = argc;
71 __targv = argv;
72 #endif
73 #if defined __i386__ || defined __x86_64__
74 _controlfp(_PC_53, _MCW_PC);
75 #endif
76 return _tmain(__argc, __targv, _tenviron);
79 // =============================================