From: Bruno Haible Date: Tue, 14 Jan 2003 13:37:56 +0000 (+0000) Subject: Don't require alloca.c. X-Git-Tag: v0.12~1170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37107dbfb1a1506baa6e9def085c04dcaca7b191;p=thirdparty%2Fgettext.git Don't require alloca.c. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 0baf3c0d3..b34d1e333 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2002-12-11 Bruno Haible + + * setenv.c (alloca): Fall back to malloc. + (freea): New macro. + (setenv): Use freea() to free memory allocated with alloca(). + 2003-01-12 Bruno Haible * classpath.h: New file. diff --git a/lib/setenv.c b/lib/setenv.c index 17f8c6c0c..7c8ab7a3e 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -39,6 +39,15 @@ extern int errno; # include #endif +/* For those losing systems which don't have 'alloca' we have to add + some additional code emulating it. */ +#if _LIBC || HAVE_ALLOCA +# define freea(p) /* nothing */ +#else +# define alloca(n) malloc (n) +# define freea(p) free (p) +#endif + #if !_LIBC # define __environ environ # ifndef HAVE_ENVIRON_DECL @@ -176,6 +185,9 @@ __add_to_environ (const char *name, const char *value, const char *combined, new_environ[size] = (char *) malloc (namelen + 1 + vallen); if (new_environ[size] == NULL) { +#ifdef USE_TSEARCH + freea (new_value); +#endif __set_errno (ENOMEM); UNLOCK; return -1; @@ -193,6 +205,9 @@ __add_to_environ (const char *name, const char *value, const char *combined, user string or not. */ STORE_VALUE (new_environ[size]); } +#ifdef USE_TSEARCH + freea (new_value); +#endif } if (__environ != last_environ) @@ -230,6 +245,9 @@ __add_to_environ (const char *name, const char *value, const char *combined, np = malloc (namelen + 1 + vallen); if (np == NULL) { +#ifdef USE_TSEARCH + freea (new_value); +#endif UNLOCK; return -1; } @@ -244,6 +262,9 @@ __add_to_environ (const char *name, const char *value, const char *combined, /* And remember the value. */ STORE_VALUE (np); } +#ifdef USE_TSEARCH + freea (new_value); +#endif } *ep = np;