emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111156: Provide unsetenv for MS-Wind


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111156: Provide unsetenv for MS-Windows and make putenv Posix-compatible.
Date: Sat, 08 Dec 2012 13:32:10 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111156
fixes bug: http://debbugs.gnu.org/13070
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Sat 2012-12-08 13:32:10 +0200
message:
  Provide unsetenv for MS-Windows and make putenv Posix-compatible.
  
   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.
modified:
  nt/ChangeLog
  nt/config.nt
  nt/inc/ms-w32.h
  src/ChangeLog
  src/w32.c
=== modified file 'nt/ChangeLog'
--- a/nt/ChangeLog      2012-12-01 20:09:30 +0000
+++ b/nt/ChangeLog      2012-12-08 11:32:10 +0000
@@ -1,3 +1,9 @@
+2012-12-08  Eli Zaretskii  <address@hidden>
+
+       * inc/ms-w32.h (putenv): Redirect to sys_putenv.
+
+       * config.nt (HAVE_UNSETENV): Define to 1.
+
 2012-12-01  Juanma Barranquero  <address@hidden>
 
        * config.nt: Sync with autogen/config.in.

=== modified file 'nt/config.nt'
--- a/nt/config.nt      2012-12-01 20:09:30 +0000
+++ b/nt/config.nt      2012-12-08 11:32:10 +0000
@@ -993,6 +993,9 @@
 /* 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
 

=== modified file 'nt/inc/ms-w32.h'
--- a/nt/inc/ms-w32.h   2012-11-27 03:10:32 +0000
+++ b/nt/inc/ms-w32.h   2012-12-08 11:32:10 +0000
@@ -376,6 +376,12 @@
 #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);
 

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-12-08 11:05:39 +0000
+++ b/src/ChangeLog     2012-12-08 11:32:10 +0000
@@ -1,3 +1,7 @@
+2012-12-08  Eli Zaretskii  <address@hidden>
+
+       * w32.c (unsetenv, sys_putenv): New functions.
+
 2012-12-08  Chong Yidong  <address@hidden>
 
        * editfns.c (Finsert_char): Make the error message more

=== modified file 'src/w32.c'
--- a/src/w32.c 2012-12-03 01:08:31 +0000
+++ b/src/w32.c 2012-12-08 11:32:10 +0000
@@ -1544,6 +1544,50 @@
   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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]