*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;
#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
}
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);
win32_setprotoent
win32_setservent
win32_getenv
+win32_putenv
win32_perror
win32_setbuf
win32_setvbuf
};
virtual int Putenv(const char *envstring, int &err)
{
- return putenv(envstring);
+ return win32_putenv(envstring);
};
virtual char* LibPath(char *pl)
{
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
#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);
#ifndef USE_WIN32_RTL_ENV
#undef getenv
#define getenv win32_getenv
+#undef putenv
+#define putenv win32_putenv
#endif
#endif /* WIN32IO_IS_STDIO */