4 * Source code for the startup proceedures used by all programs. This code
5 * is compiled to make crt0.o, which should be located in the library path.
7 * This code is part of the Mingw32 package.
10 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
12 * THIS SOFTWARE IS NOT COPYRIGHTED
14 * This source code is offered for use in the public domain. You may
15 * use, modify or distribute it freely.
17 * This code is distributed in the hope that it will be useful but
18 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
19 * DISCLAMED. This includes but is not limited to warrenties of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 #include <msvcrt/stdlib.h>
30 #include <msvcrt/stdio.h>
31 #include <msvcrt/io.h>
32 #include <msvcrt/fcntl.h>
33 #include <msvcrt/process.h>
34 #include <msvcrt/float.h>
37 /* NOTE: The code for initializing the _argv, _argc, and environ variables
38 * has been moved to a separate .c file which is included in both
39 * crt1.c and dllcrt1.c. This means changes in the code don't have to
40 * be manually synchronized, but it does lead to this not-generally-
41 * a-good-idea use of include. */
44 extern int main(int, char**, char**);
47 * Setup the default file handles to have the _CRT_fmode mode, as well as
48 * any new files created by the user.
50 extern unsigned int _CRT_fmode
;
53 _mingw32_init_fmode (void)
55 /* Don't set the file mode if the user hasn't set any value for it. */
61 * This overrides the default file mode settings for stdin,
62 * stdout and stderr. At first I thought you would have to
63 * test with isatty, but it seems that the DOS console at
64 * least is smart enough to handle _O_BINARY stdout and
65 * still display correctly.
69 _setmode (_fileno(stdin
), _CRT_fmode
);
73 _setmode (_fileno(stdout
), _CRT_fmode
);
77 _setmode (_fileno(stderr
), _CRT_fmode
);
84 * The function mainCRTStartup is the entry point for all console programs.
92 * I have been told that this is the correct thing to do. You
93 * have to uncomment the prototype of SetUnhandledExceptionFilter
94 * in the GNU Win32 API headers for this to work. The type it
95 * expects is a pointer to a function of the same type as
96 * UnhandledExceptionFilter, which is prototyped just above
99 //SetUnhandledExceptionFilter (NULL);
102 * Initialize floating point unit.
104 _fpreset (); /* Supplied by the runtime library. */
107 * Set up __argc, __argv and _environ.
109 _mingw32_init_mainargs();
112 * Sets the default file mode for stdin, stdout and stderr, as well
113 * as files later opened by the user, to _CRT_fmode.
114 * NOTE: DLLs don't do this because that would be rude!
116 _mingw32_init_fmode();
119 * Call the main function. If the user does not supply one
120 * the one in the 'libmingw32.a' library will be linked in, and
121 * that one calls WinMain. See main.c in the 'lib' dir
124 nRet
= main(_argc
, _argv
, _environ
);
127 * Perform exit processing for the C library. This means
128 * flushing output and calling 'atexit' registered functions.
138 * For now the GUI startup function is the same as the console one.
139 * This simply gets rid of the annoying warning about not being able
140 * to find WinMainCRTStartup when linking GUI applications.
143 WinMainCRTStartup (void)
145 return mainCRTStartup();
148 /* With the EGCS build from Mumit Khan (or apparently b19 from Cygnus) this
149 * is no longer necessary. */
152 * This section terminates the list of imports under GCC. If you do not
153 * include this then you will have problems when linking with DLLs.
156 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");