Update gnulib to current upstream master
[deliverable/binutils-gdb.git] / gdb / gnulib / import / canonicalize-lgpl.c
index 1c9f2ee91b96ae73063952e83c0f8ac358f390f9..4a38a4610ed69ba15e2bb3666561c44624200379 100644 (file)
@@ -1,5 +1,5 @@
 /* Return the canonical absolute name of a given file.
-   Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   Copyright (C) 1996-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This program is free software: you can redistribute it and/or modify
 #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;
+                  __set_errno (ENOMEM);
                   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;
 }
This page took 0.024891 seconds and 4 git commands to generate.