diff options
| author | Eli Zaretskii | 2012-12-08 13:32:10 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-12-08 13:32:10 +0200 |
| commit | 75ceee05671c1698e27e5188487e7e74c490f201 (patch) | |
| tree | 2e994ddbe30f7454aafe897bf7436c2ac1364a55 /src | |
| parent | e4184a20f6e23f083e461e2e3e7f3fdcc0ec5ea6 (diff) | |
| download | emacs-75ceee05671c1698e27e5188487e7e74c490f201.tar.gz emacs-75ceee05671c1698e27e5188487e7e74c490f201.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/w32.c | 44 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 8e1e422d154..3e8b8519ba3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2012-12-08 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * w32.c (unsetenv, sys_putenv): New functions. | ||
| 4 | |||
| 1 | 2012-12-08 Chong Yidong <cyd@gnu.org> | 5 | 2012-12-08 Chong Yidong <cyd@gnu.org> |
| 2 | 6 | ||
| 3 | * editfns.c (Finsert_char): Make the error message more | 7 | * editfns.c (Finsert_char): Make the error message more |
| @@ -1544,6 +1544,50 @@ is_unc_volume (const char *filename) | |||
| 1544 | return 1; | 1544 | return 1; |
| 1545 | } | 1545 | } |
| 1546 | 1546 | ||
| 1547 | /* Emulate the Posix unsetenv. */ | ||
| 1548 | int | ||
| 1549 | unsetenv (const char *name) | ||
| 1550 | { | ||
| 1551 | char *var; | ||
| 1552 | size_t name_len; | ||
| 1553 | int retval; | ||
| 1554 | |||
| 1555 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | ||
| 1556 | { | ||
| 1557 | errno = EINVAL; | ||
| 1558 | return -1; | ||
| 1559 | } | ||
| 1560 | name_len = strlen (name); | ||
| 1561 | /* MS docs says an environment variable cannot be longer than 32K. */ | ||
| 1562 | if (name_len > 32767) | ||
| 1563 | { | ||
| 1564 | errno = ENOMEM; | ||
| 1565 | return -1; | ||
| 1566 | } | ||
| 1567 | /* It is safe to use 'alloca' with 32K size, since the stack is at | ||
| 1568 | least 2MB, and we set it to 8MB in the link command line. */ | ||
| 1569 | var = alloca (name_len + 2); | ||
| 1570 | var[name_len++] = '='; | ||
| 1571 | var[name_len] = '\0'; | ||
| 1572 | return _putenv (var); | ||
| 1573 | } | ||
| 1574 | |||
| 1575 | /* MS _putenv doesn't support removing a variable when the argument | ||
| 1576 | does not include the '=' character, so we fix that here. */ | ||
| 1577 | int | ||
| 1578 | sys_putenv (char *str) | ||
| 1579 | { | ||
| 1580 | const char *const name_end = strchr (str, '='); | ||
| 1581 | |||
| 1582 | if (name_end == NULL) | ||
| 1583 | { | ||
| 1584 | /* Remove the variable from the environment. */ | ||
| 1585 | return unsetenv (str); | ||
| 1586 | } | ||
| 1587 | |||
| 1588 | return _putenv (str); | ||
| 1589 | } | ||
| 1590 | |||
| 1547 | #define REG_ROOT "SOFTWARE\\GNU\\Emacs" | 1591 | #define REG_ROOT "SOFTWARE\\GNU\\Emacs" |
| 1548 | 1592 | ||
| 1549 | LPBYTE | 1593 | LPBYTE |