1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Stub for readlink().
4 Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 /* readlink() substitute for systems that don't have a readlink() function,
31 such as DJGPP 2.03 and mingw32. */
34 readlink (const char *name, char *buf _GL_UNUSED,
35 size_t bufsize _GL_UNUSED)
39 /* In general we should use lstat() here, not stat(). But on platforms
40 without symbolic links, lstat() - if it exists - would be equivalent to
41 stat(), therefore we can use stat(). This saves us a configure check. */
42 if (stat (name, &statbuf) >= 0)
47 #else /* HAVE_READLINK */
51 /* readlink() wrapper that uses correct types, for systems like cygwin
52 1.5.x where readlink returns int, and which rejects trailing slash,
56 rpl_readlink (const char *name, char *buf, size_t bufsize)
58 # if READLINK_TRAILING_SLASH_BUG
59 size_t len = strlen (name);
60 if (len && name[len - 1] == '/')
62 /* Even if name without the slash is a symlink to a directory,
63 both lstat() and stat() must resolve the trailing slash to
64 the directory rather than the symlink. We can therefore
65 safely use stat() to distinguish between EINVAL and
66 ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
68 if (stat (name, &st) == 0)
72 # endif /* READLINK_TRAILING_SLASH_BUG */
73 return readlink (name, buf, bufsize);
76 #endif /* HAVE_READLINK */