New module 'unicase/u8-casecmp'.
[pspp] / lib / canonicalize-lgpl.c
index 14dd536dc469dd9deb2d3125b56a3e735eaa1380..3aaa310ecd2d0883e6b8e5121e214859d28d1786 100644 (file)
@@ -1,11 +1,11 @@
 /* Return the canonical absolute name of a given file.
-   Copyright (C) 1996-2003, 2005-2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-2003, 2005-2008 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
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
@@ -79,7 +78,7 @@
 # endif
 # define __readlink readlink
   /* On systems without symbolic links, call stat() instead of lstat().  */
-# if !defined S_ISNLK && !HAVE_READLINK
+# if !defined S_ISLNK && !HAVE_READLINK
 #  define lstat stat
 # endif
 #endif
@@ -135,7 +134,12 @@ __realpath (const char *name, char *resolved)
     {
       rpath = malloc (path_max);
       if (rpath == NULL)
-       return NULL;
+       {
+         /* It's easier to set errno to ENOMEM than to rely on the
+            'malloc-posix' gnulib module.  */
+         errno = ENOMEM;
+         return NULL;
+       }
     }
   else
     rpath = resolved;
@@ -209,7 +213,12 @@ __realpath (const char *name, char *resolved)
                new_size += path_max;
              new_rpath = (char *) realloc (rpath, new_size);
              if (new_rpath == NULL)
-               goto error;
+               {
+                 /* It's easier to set errno to ENOMEM than to rely on the
+                    'realloc-posix' gnulib module.  */
+                 errno = ENOMEM;
+                 goto error;
+               }
              rpath = new_rpath;
              rpath_limit = rpath + new_size;
 
@@ -251,7 +260,7 @@ __realpath (const char *name, char *resolved)
                  goto error;
                }
 
-             n = __readlink (rpath, buf, path_max);
+             n = __readlink (rpath, buf, path_max - 1);
              if (n < 0)
                {
                  int saved_errno = errno;