diff options
-rw-r--r-- | mg.c | 2 | ||||
-rw-r--r-- | util.c | 25 | ||||
-rw-r--r-- | win32/GenCAPI.pl | 5 | ||||
-rw-r--r-- | win32/makedef.pl | 1 | ||||
-rw-r--r-- | win32/perlhost.h | 2 | ||||
-rw-r--r-- | win32/win32.c | 34 | ||||
-rw-r--r-- | win32/win32iop.h | 3 |
7 files changed, 55 insertions, 17 deletions
@@ -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; @@ -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 5e7868ddf7..af71291830 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 0d9069b9fd..fa1b58081b 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 21908098a5..e514bf1342 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 2c74fc25af..7b9acd4a8f 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 12fe63e38f..c7a74444e0 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 */ |