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