src/w32.c (unsetenv, sys_putenv): New functions.
nt/inc/ms-w32.h (putenv): Redirect to sys_putenv.
nt/config.nt (HAVE_UNSETENV): Define to 1.
Fixes: debbugs:13070
+2012-12-08 Eli Zaretskii <eliz@gnu.org>
+
+ * inc/ms-w32.h (putenv): Redirect to sys_putenv.
+
+ * config.nt (HAVE_UNSETENV): Define to 1.
+
2012-12-01 Juanma Barranquero <lekktu@gmail.com>
* config.nt: Sync with autogen/config.in.
/* Define to 1 if the system has the type 'unsigned long long int'. */
#undef HAVE_UNSIGNED_LONG_LONG_INT
+/* Define to 1 if you have the `unsetenv' function. */
+#define HAVE_UNSETENV 1
+
/* Define to 1 if you have the <util.h> header file. */
#undef HAVE_UTIL_H
#define sys_nerr _sys_nerr
#endif
+/* This must be after including stdlib.h, which defines putenv on MinGW. */
+#ifdef putenv
+# undef putenv
+#endif
+#define putenv sys_putenv
+
extern int getloadavg (double *, int);
extern int getpagesize (void);
+2012-12-08 Eli Zaretskii <eliz@gnu.org>
+
+ * w32.c (unsetenv, sys_putenv): New functions.
+
2012-12-08 Chong Yidong <cyd@gnu.org>
* editfns.c (Finsert_char): Make the error message more
return 1;
}
+/* Emulate the Posix unsetenv. */
+int
+unsetenv (const char *name)
+{
+ char *var;
+ size_t name_len;
+ int retval;
+
+ if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ name_len = strlen (name);
+ /* MS docs says an environment variable cannot be longer than 32K. */
+ if (name_len > 32767)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+ /* It is safe to use 'alloca' with 32K size, since the stack is at
+ least 2MB, and we set it to 8MB in the link command line. */
+ var = alloca (name_len + 2);
+ var[name_len++] = '=';
+ var[name_len] = '\0';
+ return _putenv (var);
+}
+
+/* MS _putenv doesn't support removing a variable when the argument
+ does not include the '=' character, so we fix that here. */
+int
+sys_putenv (char *str)
+{
+ const char *const name_end = strchr (str, '=');
+
+ if (name_end == NULL)
+ {
+ /* Remove the variable from the environment. */
+ return unsetenv (str);
+ }
+
+ return _putenv (str);
+}
+
#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
LPBYTE