X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Freadlink.c;h=f83a1e0123f5e17c33433e168cf907b28db3429f;hb=23eecb48e39afd0d267d64d40ba6bf97aa865e13;hp=58379b1d0781296dbbbeb3b93a0c6fedc080a82c;hpb=5b192b3998d3b3bcea45594d180200cd44f35e3b;p=gnulib.git diff --git a/lib/readlink.c b/lib/readlink.c index 58379b1d0..f83a1e012 100644 --- a/lib/readlink.c +++ b/lib/readlink.c @@ -1,5 +1,5 @@ /* Stub for readlink(). - Copyright (C) 2003-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc. 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 @@ -29,8 +29,8 @@ such as DJGPP 2.03 and mingw32. */ ssize_t -readlink (const char *name, char *buf _UNUSED_PARAMETER_, - size_t bufsize _UNUSED_PARAMETER_) +readlink (const char *name, char *buf _GL_UNUSED, + size_t bufsize _GL_UNUSED) { struct stat statbuf; @@ -47,11 +47,27 @@ readlink (const char *name, char *buf _UNUSED_PARAMETER_, # undef readlink /* readlink() wrapper that uses correct types, for systems like cygwin - 1.5.x where readlink returns int. */ + 1.5.x where readlink returns int, and which rejects trailing slash, + for Solaris 9. */ ssize_t rpl_readlink (const char *name, char *buf, size_t bufsize) { +# if READLINK_TRAILING_SLASH_BUG + size_t len = strlen (name); + if (len && name[len - 1] == '/') + { + /* Even if name without the slash is a symlink to a directory, + both lstat() and stat() must resolve the trailing slash to + the directory rather than the symlink. We can therefore + safely use stat() to distinguish between EINVAL and + ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ + struct stat st; + if (stat (name, &st) == 0) + errno = EINVAL; + return -1; + } +# endif /* READLINK_TRAILING_SLASH_BUG */ return readlink (name, buf, bufsize); }