From: Gurusamy Sarathy Date: Fri, 12 Feb 1999 11:49:25 +0000 (+0000) Subject: support win32_putenv() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac5c734f32ccd9787762253192de0d559609abae;hp=a2093a06980c0ef77ac4631e8b8f383be904f06a;p=p5sagit%2Fp5-mst-13.2.git support win32_putenv() p4raw-id: //depot/perl@2898 --- diff --git a/mg.c b/mg.c index bab5298..ce6052f 100644 --- a/mg.c +++ b/mg.c @@ -890,7 +890,7 @@ magic_clear_all_env(SV *sv, MAGIC *mg) *end = '\0'; my_setenv(cur,Nullch); *end = '='; - cur += strlen(end+1)+1; + cur = end + strlen(end+1)+2; } else if ((len = strlen(cur))) cur += len+1; diff --git a/util.c b/util.c index 8dd7d00..db727f7 100644 --- a/util.c +++ b/util.c @@ -1607,21 +1607,16 @@ my_setenv(char *nam,char *val) #else /* !USE_WIN32_RTL_ENV */ - /* The sane way to deal with the environment. - * Has these advantages over putenv() & co.: - * * enables us to store a truly empty value in the - * environment (like in UNIX). - * * we don't have to deal with RTL globals, bugs and leaks. - * * Much faster. - * Why you may want to enable USE_WIN32_RTL_ENV: - * * environ[] and RTL functions will not reflect changes, - * which might be an issue if extensions want to access - * the env. via RTL. This cuts both ways, since RTL will - * not see changes made by extensions that call the Win32 - * functions directly, either. - * GSAR 97-06-07 - */ - SetEnvironmentVariable(nam,val); + register char *envstr; + STRLEN len = strlen(nam) + 3; + if (!val) { + val = ""; + } + len += strlen(val); + New(904, envstr, len, char); + (void)sprintf(envstr,"%s=%s",nam,val); + (void)PerlEnv_putenv(envstr); + Safefree(envstr); #endif } diff --git a/win32/GenCAPI.pl b/win32/GenCAPI.pl index 5e7868d..af71291 100644 --- a/win32/GenCAPI.pl +++ b/win32/GenCAPI.pl @@ -995,6 +995,11 @@ char* _win32_getenv(const char *name) return pPerl->PL_piENV->Getenv(name, ErrorNo()); } +int _win32_putenv(const char *name) +{ + return pPerl->PL_piENV->Putenv(name, ErrorNo()); +} + int _win32_open_osfhandle(long handle, int flags) { return pPerl->PL_piStdIO->OpenOSfhandle(handle, flags); diff --git a/win32/makedef.pl b/win32/makedef.pl index 0d9069b..fa1b580 100644 --- a/win32/makedef.pl +++ b/win32/makedef.pl @@ -497,6 +497,7 @@ win32_setnetent win32_setprotoent win32_setservent win32_getenv +win32_putenv win32_perror win32_setbuf win32_setvbuf diff --git a/win32/perlhost.h b/win32/perlhost.h index 2190809..e514bf1 100644 --- a/win32/perlhost.h +++ b/win32/perlhost.h @@ -88,7 +88,7 @@ public: }; virtual int Putenv(const char *envstring, int &err) { - return putenv(envstring); + return win32_putenv(envstring); }; virtual char* LibPath(char *pl) { diff --git a/win32/win32.c b/win32/win32.c index 2c74fc2..7b9acd4 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1002,6 +1002,40 @@ win32_getenv(const char *name) return curitem; } +DllExport int +win32_putenv(const char *name) +{ + char* curitem; + char* val; + int relval = -1; + if(name) { + New(1309,curitem,strlen(name)+1,char); + strcpy(curitem, name); + val = strchr(curitem, '='); + if(val) { + /* The sane way to deal with the environment. + * Has these advantages over putenv() & co.: + * * enables us to store a truly empty value in the + * environment (like in UNIX). + * * we don't have to deal with RTL globals, bugs and leaks. + * * Much faster. + * Why you may want to enable USE_WIN32_RTL_ENV: + * * environ[] and RTL functions will not reflect changes, + * which might be an issue if extensions want to access + * the env. via RTL. This cuts both ways, since RTL will + * not see changes made by extensions that call the Win32 + * functions directly, either. + * GSAR 97-06-07 + */ + *val++ = '\0'; + if(SetEnvironmentVariable(curitem, *val ? val : NULL)) + relval = 0; + } + Safefree(curitem); + } + return relval; +} + #endif static long diff --git a/win32/win32iop.h b/win32/win32iop.h index 12fe63e..c7a7444 100644 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@ -115,6 +115,7 @@ DllExport long win32_get_osfhandle(int fd); #ifndef USE_WIN32_RTL_ENV DllExport char* win32_getenv(const char *name); +DllExport int win32_putenv(const char *name); #endif DllExport unsigned win32_sleep(unsigned int); @@ -279,6 +280,8 @@ END_EXTERN_C #ifndef USE_WIN32_RTL_ENV #undef getenv #define getenv win32_getenv +#undef putenv +#define putenv win32_putenv #endif #endif /* WIN32IO_IS_STDIO */