# HG changeset patch # Date 1596794668 -3600 # Parent 73953fad8dc700638ae23af97effe170753d9257 Initialize MSVCRT.DLL's _pgmptr reference. * setargv.c (_setargv) [__CRT_GLOB_USE_MINGW__]: Check for... [_pgmptr == NULL] (_pgmptr): ...uninitialized; initialize it from... (GetModuleFileName): ...this. diff --git a/mingwrt/setargv.c b/mingwrt/setargv.c --- a/mingwrt/setargv.c +++ b/mingwrt/setargv.c @@ -5,12 +5,12 @@ * vector, which will subsequently be passed to the main() function; * provides a _setargv() hook, similar to that described on MSDN. * * $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 * * --------------------------------------------------------------------------- * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -34,15 +34,15 @@ * */ #define _ISOC99_SOURCE #include +#include #include #include -#define WIN32_LEAN_AND_MEAN -#include +#include /* Access to a standard 'main'-like argument count and list. */ extern int _argc; extern char ** _argv; @@ -264,9 +264,22 @@ void _setargv() * to the previously defined inline function, which avoids the * broken globbing behaviour of some more recent versions of * 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 ); + } } } /* $RCSfile$: end of file */