mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-10 11:20:28 +02:00
(scm_putenv): Handle removing variables explicitely by calling
unsetenv.
This commit is contained in:
parent
1d8c3cad87
commit
002409fe6f
1 changed files with 20 additions and 9 deletions
|
@ -1189,15 +1189,26 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
SCM_VALIDATE_STRING (1, str);
|
SCM_VALIDATE_STRING (1, str);
|
||||||
/* must make a new copy to be left in the environment, safe from gc. */
|
|
||||||
ptr = malloc (SCM_STRING_LENGTH (str) + 1);
|
if (strchr (SCM_STRING_CHARS (str), '=') == NULL)
|
||||||
if (ptr == NULL)
|
{
|
||||||
SCM_MEMORY_ERROR;
|
/* No '=' in argument means we should remove the variable from
|
||||||
strncpy (ptr, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str));
|
the environment. Not all putenvs understand this. To be
|
||||||
ptr[SCM_STRING_LENGTH (str)] = 0;
|
safe, we do it explicitely using unsetenv. */
|
||||||
rv = putenv (ptr);
|
unsetenv (SCM_STRING_CHARS (str));
|
||||||
if (rv < 0)
|
}
|
||||||
SCM_SYSERROR;
|
else
|
||||||
|
{
|
||||||
|
/* must make a new copy to be left in the environment, safe from gc. */
|
||||||
|
ptr = malloc (SCM_STRING_LENGTH (str) + 1);
|
||||||
|
if (ptr == NULL)
|
||||||
|
SCM_MEMORY_ERROR;
|
||||||
|
strncpy (ptr, SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str));
|
||||||
|
ptr[SCM_STRING_LENGTH (str)] = 0;
|
||||||
|
rv = putenv (ptr);
|
||||||
|
if (rv < 0)
|
||||||
|
SCM_SYSERROR;
|
||||||
|
}
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue