:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / misc / init.c
1 /*
2  * init.c
3  *
4  * Code to initialize standard file handles and command line arguments.
5  * This file is #included in both crt1.c and dllcrt1.c.
6  *
7  * This file is part of the Mingw32 package.
8  *
9  * Contributors:
10  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
11  *
12  *  THIS SOFTWARE IS NOT COPYRIGHTED
13  *
14  *  This source code is offered for use in the public domain. You may
15  *  use, modify or distribute it freely.
16  *
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.
21  *
22  * $Revision$
23  * $Author$
24  * $Date$
25  *
26  */
27
28 /*
29  * Access to a standard 'main'-like argument count and list. Also included
30  * is a table of environment variables.
31  */
32 int     _argc = 0;
33 char**  _argv = 0;
34
35 /* NOTE: Thanks to Pedro A. Aranda Gutiirrez <paag@tid.es> for pointing
36  * this out to me. GetMainArgs (used below) takes a fourth argument
37  * which is an int that controls the globbing of the command line. If
38  * _CRT_glob is non-zero the command line will be globbed (e.g. *.*
39  * expanded to be all files in the startup directory). In the mingw32
40  * library a _CRT_glob variable is defined as being -1, enabling
41  * this command line globbing by default. To turn it off and do all
42  * command line processing yourself (and possibly escape bogons in
43  * MS's globbing code) include a line in one of your source modules
44  * defining _CRT_glob and setting it to zero, like this:
45  *  int _CRT_glob = 0;
46  */
47 extern int      _CRT_glob;
48
49 #ifdef __MSVCRT__
50 extern void __getmainargs(int *, char***, char***, int);
51 #else
52 extern void __GetMainArgs(int *, char***, char***, int);
53 #endif
54
55 /*
56  * Initialize the _argc, _argv and environ variables.
57  */
58 static void
59 _mingw32_init_mainargs (void)
60 {
61         /* The environ variable is provided directly in stdlib.h through
62          * a dll function call. */
63         char**  dummy_environ;
64
65         /*
66          * Microsoft's runtime provides a function for doing just that.
67          */
68 #ifdef __MSVCRT__
69         (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob);
70 #else
71         /* CRTDLL version */
72         (void) __GetMainArgs(&_argc, &_argv, &dummy_environ, _CRT_glob);
73 #endif
74 }
75