1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 23:00:22 +02:00

(scm_putenv): Correction to "len" variable, was defined only

for __MINGW32__ but used under any !HAVE_UNSETENV (such as solaris).
Move it to where it's used.  Reported by Hugh Sasse.
This commit is contained in:
Kevin Ryde 2007-01-15 21:18:20 +00:00
parent 9a43154a6a
commit 2c1ca00535

View file

@ -1326,9 +1326,6 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
{ {
int rv; int rv;
char *c_str = scm_to_locale_string (str); char *c_str = scm_to_locale_string (str);
#ifdef __MINGW32__
size_t len = strlen (c_str);
#endif
if (strchr (c_str, '=') == NULL) if (strchr (c_str, '=') == NULL)
{ {
@ -1343,6 +1340,7 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
/* On e.g. Win32 hosts putenv() called with 'name=' removes the /* On e.g. Win32 hosts putenv() called with 'name=' removes the
environment variable 'name'. */ environment variable 'name'. */
int e; int e;
size_t len = strlen (c_str);
char *ptr = scm_malloc (len + 2); char *ptr = scm_malloc (len + 2);
strcpy (ptr, c_str); strcpy (ptr, c_str);
strcpy (ptr+len, "="); strcpy (ptr+len, "=");
@ -1362,26 +1360,29 @@ SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
by getenv. It's not enough just to modify the string we set, by getenv. It's not enough just to modify the string we set,
because MINGW putenv copies it. */ because MINGW putenv copies it. */
if (c_str[len-1] == '=') {
{ size_t len = strlen (c_str);
char *ptr = scm_malloc (len+2); if (c_str[len-1] == '=')
strcpy (ptr, c_str); {
strcpy (ptr+len, " "); char *ptr = scm_malloc (len+2);
rv = putenv (ptr); strcpy (ptr, c_str);
if (rv < 0) strcpy (ptr+len, " ");
{ rv = putenv (ptr);
int eno = errno; if (rv < 0)
free (c_str); {
errno = eno; int eno = errno;
SCM_SYSERROR; free (c_str);
} errno = eno;
/* truncate to just the name */ SCM_SYSERROR;
c_str[len-1] = '\0'; }
ptr = getenv (c_str); /* truncate to just the name */
if (ptr) c_str[len-1] = '\0';
ptr[0] = '\0'; ptr = getenv (c_str);
return SCM_UNSPECIFIED; if (ptr)
} ptr[0] = '\0';
return SCM_UNSPECIFIED;
}
}
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */
/* Leave c_str in the environment. */ /* Leave c_str in the environment. */