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.

Fixes: debbugs:13070
This commit is contained in:
Eli Zaretskii 2012-12-08 13:32:10 +02:00
parent e4184a20f6
commit 75ceee0567
5 changed files with 63 additions and 0 deletions

View file

@ -1,3 +1,9 @@
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.

View file

@ -993,6 +993,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* 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

View file

@ -376,6 +376,12 @@ extern char *get_emacs_configuration_options (void);
#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);

View file

@ -1,3 +1,7 @@
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

View file

@ -1544,6 +1544,50 @@ is_unc_volume (const char *filename)
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