xref: /reactos/sdk/lib/ucrt/startup/argv_data.cpp (revision 04e0dc4a)
1*04e0dc4aSTimo Kreuzer //
2*04e0dc4aSTimo Kreuzer // argv_data.cpp
3*04e0dc4aSTimo Kreuzer //
4*04e0dc4aSTimo Kreuzer //      Copyright (c) Microsoft Corporation.  All rights reserved.
5*04e0dc4aSTimo Kreuzer //
6*04e0dc4aSTimo Kreuzer // This file defines the global data that stores the command line with which the
7*04e0dc4aSTimo Kreuzer // program was executed, along with the parsed arguments (if the arguments were
8*04e0dc4aSTimo Kreuzer // parsed), and the accessors for the global data.
9*04e0dc4aSTimo Kreuzer //
10*04e0dc4aSTimo Kreuzer #include <corecrt_internal.h>
11*04e0dc4aSTimo Kreuzer 
12*04e0dc4aSTimo Kreuzer 
13*04e0dc4aSTimo Kreuzer 
14*04e0dc4aSTimo Kreuzer extern "C" {
15*04e0dc4aSTimo Kreuzer 
16*04e0dc4aSTimo Kreuzer 
17*04e0dc4aSTimo Kreuzer // Note:  In general, either the narrow or wide string variables will be set,
18*04e0dc4aSTimo Kreuzer // but not both.  These get initialized by the CRT startup sequence before any
19*04e0dc4aSTimo Kreuzer // user code is executed.  There are cases where any or all of the pointers may
20*04e0dc4aSTimo Kreuzer // be null during execution.  Do not assume that they are non-null.
21*04e0dc4aSTimo Kreuzer 
22*04e0dc4aSTimo Kreuzer int       __argc   = 0;       // The number of arguments in __argv or __wargv
23*04e0dc4aSTimo Kreuzer char**    __argv   = nullptr; // The arguments as narrow strings
24*04e0dc4aSTimo Kreuzer wchar_t** __wargv  = nullptr; // The arguments as wide strings
25*04e0dc4aSTimo Kreuzer char*     _pgmptr  = nullptr; // The name of the program as a narrow string
26*04e0dc4aSTimo Kreuzer wchar_t*  _wpgmptr = nullptr; // The name of the program as a wide string
27*04e0dc4aSTimo Kreuzer char*     _acmdln  = nullptr; // The raw command line as a narrow string
28*04e0dc4aSTimo Kreuzer wchar_t*  _wcmdln  = nullptr; // The raw command line as a wide string
29*04e0dc4aSTimo Kreuzer 
30*04e0dc4aSTimo Kreuzer _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
31*04e0dc4aSTimo Kreuzer 
__p___argc()32*04e0dc4aSTimo Kreuzer int*       __cdecl __p___argc()   { return &__argc;   }
__p___argv()33*04e0dc4aSTimo Kreuzer char***    __cdecl __p___argv()   { return &__argv;   }
__p___wargv()34*04e0dc4aSTimo Kreuzer wchar_t*** __cdecl __p___wargv()  { return &__wargv;  }
__p__pgmptr()35*04e0dc4aSTimo Kreuzer char**     __cdecl __p__pgmptr()  { return &_pgmptr;  }
__p__wpgmptr()36*04e0dc4aSTimo Kreuzer wchar_t**  __cdecl __p__wpgmptr() { return &_wpgmptr; }
__p__acmdln()37*04e0dc4aSTimo Kreuzer char**     __cdecl __p__acmdln()  { return &_acmdln;  }
__p__wcmdln()38*04e0dc4aSTimo Kreuzer wchar_t**  __cdecl __p__wcmdln()  { return &_wcmdln;  }
39*04e0dc4aSTimo Kreuzer 
_get_wpgmptr(wchar_t ** const result)40*04e0dc4aSTimo Kreuzer errno_t __cdecl _get_wpgmptr(wchar_t** const result)
41*04e0dc4aSTimo Kreuzer {
42*04e0dc4aSTimo Kreuzer     _VALIDATE_RETURN_ERRCODE(result   != nullptr, EINVAL);
43*04e0dc4aSTimo Kreuzer     _VALIDATE_RETURN_ERRCODE(_wpgmptr != nullptr, EINVAL);
44*04e0dc4aSTimo Kreuzer 
45*04e0dc4aSTimo Kreuzer     *result = _wpgmptr;
46*04e0dc4aSTimo Kreuzer     return 0;
47*04e0dc4aSTimo Kreuzer }
48*04e0dc4aSTimo Kreuzer 
_get_pgmptr(char ** const result)49*04e0dc4aSTimo Kreuzer errno_t __cdecl _get_pgmptr(char** const result)
50*04e0dc4aSTimo Kreuzer {
51*04e0dc4aSTimo Kreuzer     _VALIDATE_RETURN_ERRCODE(result  != nullptr, EINVAL);
52*04e0dc4aSTimo Kreuzer     _VALIDATE_RETURN_ERRCODE(_pgmptr != nullptr, EINVAL);
53*04e0dc4aSTimo Kreuzer     *result = _pgmptr;
54*04e0dc4aSTimo Kreuzer     return 0;
55*04e0dc4aSTimo Kreuzer }
56*04e0dc4aSTimo Kreuzer 
57*04e0dc4aSTimo Kreuzer _END_SECURE_CRT_DEPRECATION_DISABLE
58*04e0dc4aSTimo Kreuzer 
59*04e0dc4aSTimo Kreuzer 
60*04e0dc4aSTimo Kreuzer 
__acrt_initialize_command_line()61*04e0dc4aSTimo Kreuzer bool __cdecl __acrt_initialize_command_line()
62*04e0dc4aSTimo Kreuzer {
63*04e0dc4aSTimo Kreuzer     _acmdln = GetCommandLineA();
64*04e0dc4aSTimo Kreuzer     _wcmdln = GetCommandLineW();
65*04e0dc4aSTimo Kreuzer     return true;
66*04e0dc4aSTimo Kreuzer }
67*04e0dc4aSTimo Kreuzer 
__acrt_uninitialize_command_line(bool const)68*04e0dc4aSTimo Kreuzer bool __cdecl __acrt_uninitialize_command_line(bool const /* terminating */)
69*04e0dc4aSTimo Kreuzer {
70*04e0dc4aSTimo Kreuzer     return true;
71*04e0dc4aSTimo Kreuzer }
72*04e0dc4aSTimo Kreuzer 
73*04e0dc4aSTimo Kreuzer 
74*04e0dc4aSTimo Kreuzer 
75*04e0dc4aSTimo Kreuzer } // extern "C"
76