From cb35fabe0d0d53025e864eb9df456d9d0719c81a Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Fri, 7 Aug 2020 11:04:28 +0100 Subject: [PATCH] Initialize MSVCRT.DLL's _pgmptr reference. --- mingwrt/ChangeLog | 8 ++++++++ mingwrt/setargv.c | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 7ea8931..b3eb4f4 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,11 @@ +2020-08-07 Keith Marshall + + Initialize MSVCRT.DLL's _pgmptr reference. + + * setargv.c (_setargv) [__CRT_GLOB_USE_MINGW__]: Check for... + [_pgmptr == NULL] (_pgmptr): ...uninitialized; initialize it from... + (GetModuleFileName): ...this. + 2020-07-23 Keith Marshall Prepare and publish MinGW.org WSL-5.4.1 release. diff --git a/mingwrt/setargv.c b/mingwrt/setargv.c index 712ad83..b2080bb 100644 --- a/mingwrt/setargv.c +++ b/mingwrt/setargv.c @@ -7,8 +7,8 @@ * * $Id$ * - * Written by Keith Marshall - * Copyright (C) 2014, 2017, 2018, MinGW.org Project + * Written by Keith Marshall + * Copyright (C) 2014, 2017, 2018, 2020, MinGW.org Project * * --------------------------------------------------------------------------- * @@ -36,11 +36,11 @@ #define _ISOC99_SOURCE #include +#include #include #include -#define WIN32_LEAN_AND_MEAN -#include +#include /* Access to a standard 'main'-like argument count and list. */ @@ -266,6 +266,19 @@ void _setargv() * MSVCRT.DLL */ __mingw32_setargv( GetCommandLine() ); + + /* In addition to setting up _argc and _argv, Microsoft's + * setup routine, as invoked by __mingw32_init_mainargs(), + * appears to initialize MSVCRT.DLL's _pgmptr reference, to + * point to a string representing the full path name of the + * calling executable; mimic this behaviour. + */ + if( _pgmptr == NULL ) + { char buf[MAX_PATH]; + unsigned int len = GetModuleFileName( NULL, buf, MAX_PATH ); + if( (len != 0) && (len < MAX_PATH) ) + _pgmptr = strdup( buf ); + } } } -- 2.11.0