From: Gurusamy Sarathy Date: Sun, 22 Jun 1997 05:34:00 +0000 (+1200) Subject: getenv() after my_setenv() gets old entry on Win32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0551aaa8f66eb12adb34e496ae8608b54066193c;p=p5sagit%2Fp5-mst-13.2.git getenv() after my_setenv() gets old entry on Win32 Perl uses the environment to communicate the -d:DProf switch to itself. Since the win32 code sets the operating system's env block directly when my_setenv() is called, calls to the RTL's getenv() won't see the changed environment, so the -d:Foo option is not honored. The attached patch fixes the problem by supplying our own getenv() equivalent. p5p-msgid: 199706231700.NAA23400@aatma.engin.umich.edu --- diff --git a/win32/win32.c b/win32/win32.c index 3d226ce..055eaf9 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -777,6 +777,28 @@ win32_stat(const char *path, struct stat *buffer) return stat(p, buffer); } +#ifndef USE_WIN32_RTL_ENV + +DllExport char * +win32_getenv(const char *name) +{ + static char *curitem = Nullch; + static DWORD curlen = 512; + DWORD needlen; + if (!curitem) + New(1305,curitem,curlen,char); + if (!(needlen = GetEnvironmentVariable(name,curitem,curlen))) + return Nullch; + while (needlen > curlen) { + Renew(curitem,needlen,char); + curlen = needlen; + needlen = GetEnvironmentVariable(name,curitem,curlen); + } + return curitem; +} + +#endif + #undef times int mytimes(struct tms *timebuf) diff --git a/win32/win32.h b/win32/win32.h index c6746d2..5d15eb2 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -64,6 +64,12 @@ extern char *staticlinkmodules[]; * facilities for accessing the same. See note in util.c/my_setenv(). */ /*#define USE_WIN32_RTL_ENV */ + +#ifndef USE_WIN32_RTL_ENV +#undef getenv +#define getenv win32_getenv +#endif + #define USE_SOCKETS_AS_HANDLES #ifndef USE_SOCKETS_AS_HANDLES extern FILE *myfdopen(int, char *);