0f6f902274ae71180b51b17bf89327575b4de2ef
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.
24 * $Date: 1999/04/23 18:42:21 $
28 #include <crtdll/stdlib.h>
29 #include <crtdll/stdio.h>
30 #include <crtdll/io.h>
31 #include <crtdll/fcntl.h>
32 #include <crtdll/process.h>
33 #include <crtdll/float.h>
36 /* NOTE: The code for initializing the _argv, _argc, and environ variables
37 * has been moved to a separate .c file which is included in both
38 * crt1.c and dllcrt1.c. This means changes in the code don't have to
39 * be manually synchronized, but it does lead to this not-generally-
40 * a-good-idea use of include. */
43 extern int main(int, char**, char**);
46 * Setup the default file handles to have the _CRT_fmode mode, as well as
47 * any new files created by the user.
49 extern unsigned int _CRT_fmode
;
52 _mingw32_init_fmode (void)
54 /* Don't set the file mode if the user hasn't set any value for it. */
60 * This overrides the default file mode settings for stdin,
61 * stdout and stderr. At first I thought you would have to
62 * test with isatty, but it seems that the DOS console at
63 * least is smart enough to handle _O_BINARY stdout and
64 * still display correctly.
68 _setmode (_fileno(stdin
), _CRT_fmode
);
72 _setmode (_fileno(stdout
), _CRT_fmode
);
76 _setmode (_fileno(stderr
), _CRT_fmode
);
83 * The function mainCRTStartup is the entry point for all console programs.
91 * I have been told that this is the correct thing to do. You
92 * have to uncomment the prototype of SetUnhandledExceptionFilter
93 * in the GNU Win32 API headers for this to work. The type it
94 * expects is a pointer to a function of the same type as
95 * UnhandledExceptionFilter, which is prototyped just above
98 //SetUnhandledExceptionFilter (NULL);
101 * Initialize floating point unit.
103 _fpreset (); /* Supplied by the runtime library. */
106 * Set up __argc, __argv and _environ.
108 _mingw32_init_mainargs();
111 * Sets the default file mode for stdin, stdout and stderr, as well
112 * as files later opened by the user, to _CRT_fmode.
113 * NOTE: DLLs don't do this because that would be rude!
115 _mingw32_init_fmode();
118 * Call the main function. If the user does not supply one
119 * the one in the 'libmingw32.a' library will be linked in, and
120 * that one calls WinMain. See main.c in the 'lib' dir
123 nRet
= main(_argc
, _argv
, _environ
);
126 * Perform exit processing for the C library. This means
127 * flushing output and calling 'atexit' registered functions.
137 * For now the GUI startup function is the same as the console one.
138 * This simply gets rid of the annoying warning about not being able
139 * to find WinMainCRTStartup when linking GUI applications.
142 WinMainCRTStartup (void)
144 return mainCRTStartup();
147 /* With the EGCS build from Mumit Khan (or apparently b19 from Cygnus) this
148 * is no longer necessary. */
151 * This section terminates the list of imports under GCC. If you do not
152 * include this then you will have problems when linking with DLLs.
155 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");