/* Return the canonical absolute name of a given file.
- Copyright (C) 1996-2003, 2005-2006 Free Software Foundation, Inc.
+ Copyright (C) 1996-2003, 2005-2007 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
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>
# define __canonicalize_file_name canonicalize_file_name
# define __realpath rpl_realpath
# include "pathmax.h"
-# include "allocsa.h"
+# include "malloca.h"
# if HAVE_GETCWD
# ifdef VMS
/* We want the directory in Unix syntax, not in VMS syntax. */
char *rpath, *dest, *extra_buf = NULL;
const char *start, *end, *rpath_limit;
long int path_max;
-#ifdef S_ISLNK
+#if HAVE_READLINK
int num_links = 0;
#endif
{
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;
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;
#endif
goto error;
-#ifdef S_ISLNK
+#if HAVE_READLINK
if (S_ISLNK (st.st_mode))
{
char *buf;
goto error;
}
- buf = allocsa (path_max);
+ buf = malloca (path_max);
if (!buf)
{
errno = ENOMEM;
if (n < 0)
{
int saved_errno = errno;
- freesa (buf);
+ freea (buf);
errno = saved_errno;
goto error;
}
if (!extra_buf)
{
- extra_buf = allocsa (path_max);
+ extra_buf = malloca (path_max);
if (!extra_buf)
{
- freesa (buf);
+ freea (buf);
errno = ENOMEM;
goto error;
}
len = strlen (end);
if ((long int) (n + len) >= path_max)
{
- freesa (buf);
+ freea (buf);
__set_errno (ENAMETOOLONG);
goto error;
}
*dest = '\0';
if (extra_buf)
- freesa (extra_buf);
+ freea (extra_buf);
return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath;
{
int saved_errno = errno;
if (extra_buf)
- freesa (extra_buf);
+ freea (extra_buf);
if (resolved)
strcpy (resolved, rpath);
else