]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Don't require alloca.c.
authorBruno Haible <bruno@clisp.org>
Tue, 14 Jan 2003 13:37:56 +0000 (13:37 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:08:56 +0000 (12:08 +0200)
lib/ChangeLog
lib/setenv.c

index 0baf3c0d3b81504c1dafc22b8b08bb2a0f829da9..b34d1e333f4fbff75591e5515b4d1fd348610c59 100644 (file)
@@ -1,3 +1,9 @@
+2002-12-11  Bruno Haible  <bruno@clisp.org>
+
+       * setenv.c (alloca): Fall back to malloc.
+       (freea): New macro.
+       (setenv): Use freea() to free memory allocated with alloca().
+
 2003-01-12  Bruno Haible  <bruno@clisp.org>
 
        * classpath.h: New file.
index 17f8c6c0c31cd5f70cf71165a71bad55eb2ff356..7c8ab7a3e1281251b9131da329862a50b7a2c685 100644 (file)
@@ -39,6 +39,15 @@ extern int errno;
 # include <unistd.h>
 #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;