OSDN Git Service

61522b039e5458a4e484a3f949ad303f7a83e3b5
[mingw/mingw-org-wsl.git] / src / libcrt / crt / init.c
1 /**
2  * @file init.c
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Code to initialize standard file handles and command line arguments.
27  * This file is #included in both crt1.c and dllcrt1.c.
28  */
29
30 /*
31  * Access to a standard 'main'-like argument count and list. Also included
32  * is a table of environment variables.
33  */
34 int _argc = 0;
35 char **_argv = 0;
36
37 /* NOTE: Thanks to Pedro A. Aranda Gutiirrez <paag@tid.es> for pointing
38  * this out to me. GetMainArgs (used below) takes a fourth argument
39  * which is an int that controls the globbing of the command line. If
40  * _CRT_glob is non-zero the command line will be globbed (e.g. *.*
41  * expanded to be all files in the startup directory). In the mingw32
42  * library a _CRT_glob variable is defined as being -1, enabling
43  * this command line globbing by default. To turn it off and do all
44  * command line processing yourself (and possibly escape bogons in
45  * MS's globbing code) include a line in one of your source modules
46  * defining _CRT_glob and setting it to zero, like this:
47  *  int _CRT_glob = 0;
48  */
49 extern int _CRT_glob;
50
51 #ifdef __MSVCRT__
52 typedef struct {
53   int newmode;
54 } _startupinfo;
55 extern void __getmainargs (int *, char ***, char ***, int, _startupinfo *);
56 #else
57 extern void __GetMainArgs (int *, char ***, char ***, int);
58 #endif
59
60 /*
61  * Initialize the _argc, _argv and environ variables.
62  */
63 static void
64 _mingw32_init_mainargs ()
65 {
66   /* The environ variable is provided directly in stdlib.h through
67    * a dll function call. */
68   char **dummy_environ;
69 #ifdef __MSVCRT__
70   _startupinfo start_info;
71   start_info.newmode = 0;
72 #endif
73
74   /*
75    * Microsoft's runtime provides a function for doing just that.
76    */
77 #ifdef __MSVCRT__
78   (void) __getmainargs (&_argc, &_argv, &dummy_environ, _CRT_glob, 
79                         &start_info);
80 #else
81   /* CRTDLL version */
82   (void) __GetMainArgs (&_argc, &_argv, &dummy_environ, _CRT_glob);
83 #endif
84 }
85