getdelim: remove dependency on realloc-posix
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Aug 2016 22:01:50 +0000 (15:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Aug 2016 22:03:42 +0000 (15:03 -0700)
* lib/canonicalize-lgpl.c (alloc_failed)
[!FUNC_REALPATH_WORKS || defined _LIBC]: New function,
(__realpath) [!FUNC_REALPATH_WORKS || defined _LIBC]: Use it.
Use __set_errno where needed, for consistency.
* lib/getdelim.c (alloc_failed): New function.
(getdelim): Use it.
* modules/getdelim (Depends-on): Remove realloc-posix.

ChangeLog
lib/canonicalize-lgpl.c
lib/getdelim.c
modules/getdelim

index 07b00477dc99ea8ba940cce9176eb6a2f2eab7b1..e899eb4b7455ef621a08926a2e1630d24ba14dd5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-08-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+       getdelim: remove dependency on realloc-posix
+       * lib/canonicalize-lgpl.c (alloc_failed)
+       [!FUNC_REALPATH_WORKS || defined _LIBC]: New function,
+       (__realpath) [!FUNC_REALPATH_WORKS || defined _LIBC]: Use it.
+       Use __set_errno where needed, for consistency.
+       * lib/getdelim.c (alloc_failed): New function.
+       (getdelim): Use it.
+
 2016-08-09  Assaf Gordon  <assafgordon@gmail.com>
 
        parse-datetime: add optional debug printing
index 1d0bf6553a75740064addb1f760b2363941c765c..da83da34718de9b4ce6a6259d304496139cb3879 100644 (file)
 #endif
 
 #if !FUNC_REALPATH_WORKS || defined _LIBC
+
+static void
+alloc_failed (void)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* Avoid errno problem without using the malloc or realloc modules; see:
+     http://lists.gnu.org/archive/html/bug-gnulib/2016-08/msg00025.html  */
+  errno = ENOMEM;
+#endif
+}
+
 /* Return the canonical absolute name of file NAME.  A canonical name
    does not contain any ".", ".." components nor any repeated path
    separators ('/') or symlinks.  All path components must exist.  If
@@ -135,9 +146,7 @@ __realpath (const char *name, char *resolved)
       rpath = malloc (path_max);
       if (rpath == NULL)
         {
-          /* It's easier to set errno to ENOMEM than to rely on the
-             'malloc-posix' gnulib module.  */
-          errno = ENOMEM;
+          alloc_failed ();
           return NULL;
         }
     }
@@ -238,9 +247,7 @@ __realpath (const char *name, char *resolved)
               new_rpath = (char *) realloc (rpath, new_size);
               if (new_rpath == NULL)
                 {
-                  /* It's easier to set errno to ENOMEM than to rely on the
-                     'realloc-posix' gnulib module.  */
-                  errno = ENOMEM;
+                  alloc_failed ();
                   goto error;
                 }
               rpath = new_rpath;
@@ -278,7 +285,7 @@ __realpath (const char *name, char *resolved)
               buf = malloca (path_max);
               if (!buf)
                 {
-                  errno = ENOMEM;
+                  alloc_failed ();
                   goto error;
                 }
 
@@ -287,7 +294,7 @@ __realpath (const char *name, char *resolved)
                 {
                   int saved_errno = errno;
                   freea (buf);
-                  errno = saved_errno;
+                  __set_errno (saved_errno);
                   goto error;
                 }
               buf[n] = '\0';
@@ -298,7 +305,7 @@ __realpath (const char *name, char *resolved)
                   if (!extra_buf)
                     {
                       freea (buf);
-                      errno = ENOMEM;
+                      __set_errno (ENOMEM);
                       goto error;
                     }
                 }
@@ -370,7 +377,7 @@ error:
       freea (extra_buf);
     if (resolved == NULL)
       free (rpath);
-    errno = saved_errno;
+    __set_errno (saved_errno);
   }
   return NULL;
 }
index 68a6f3402d4ee2b0039da6807d6054c861492170..706c2ed3c7fe6a0994ac22bc2bdc4b6a7a711a27 100644 (file)
 # define getc_maybe_unlocked(fp)        getc_unlocked(fp)
 #endif
 
+static void
+alloc_failed (void)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* Avoid errno problem without using the realloc module; see:
+     http://lists.gnu.org/archive/html/bug-gnulib/2016-08/msg00025.html  */
+  errno = ENOMEM;
+#endif
+}
+
 /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
    NUL-terminate it).  *LINEPTR is a pointer returned from malloc (or
    NULL), pointing to *N characters of space.  It is realloc'ed as
@@ -74,6 +84,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
       new_lineptr = (char *) realloc (*lineptr, *n);
       if (new_lineptr == NULL)
         {
+          alloc_failed ();
           result = -1;
           goto unlock_return;
         }
@@ -111,6 +122,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
           new_lineptr = (char *) realloc (*lineptr, needed);
           if (new_lineptr == NULL)
             {
+              alloc_failed ();
               result = -1;
               goto unlock_return;
             }
index e84558cc2e2024aa145ca906185d7d7d1ea7f2c4..ee7116500c2b19bf57e487ee9b57ef7865d3a885 100644 (file)
@@ -9,7 +9,6 @@ Depends-on:
 stdio
 extensions
 stdint          [test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1]
-realloc-posix   [test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1]
 errno           [test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1]
 
 configure.ac: