1*63eb84d1Schristos /* Stub for readlink().
2*63eb84d1Schristos Copyright (C) 2003-2006 Free Software Foundation, Inc.
3*63eb84d1Schristos
4*63eb84d1Schristos This program is free software; you can redistribute it and/or modify
5*63eb84d1Schristos it under the terms of the GNU General Public License as published by
6*63eb84d1Schristos the Free Software Foundation; either version 2, or (at your option)
7*63eb84d1Schristos any later version.
8*63eb84d1Schristos
9*63eb84d1Schristos This program is distributed in the hope that it will be useful,
10*63eb84d1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
11*63eb84d1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*63eb84d1Schristos GNU General Public License for more details.
13*63eb84d1Schristos
14*63eb84d1Schristos You should have received a copy of the GNU General Public License
15*63eb84d1Schristos along with this program; if not, write to the Free Software Foundation,
16*63eb84d1Schristos Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17*63eb84d1Schristos
18*63eb84d1Schristos #include <config.h>
19*63eb84d1Schristos
20*63eb84d1Schristos #include <errno.h>
21*63eb84d1Schristos #include <sys/types.h>
22*63eb84d1Schristos #include <sys/stat.h>
23*63eb84d1Schristos #include <stddef.h>
24*63eb84d1Schristos
25*63eb84d1Schristos #if !HAVE_READLINK
26*63eb84d1Schristos
27*63eb84d1Schristos /* readlink() substitute for systems that don't have a readlink() function,
28*63eb84d1Schristos such as DJGPP 2.03 and mingw32. */
29*63eb84d1Schristos
30*63eb84d1Schristos /* The official POSIX return type of readlink() is ssize_t, but since here
31*63eb84d1Schristos we have no declaration in a public header file, we use 'int' as return
32*63eb84d1Schristos type. */
33*63eb84d1Schristos
34*63eb84d1Schristos int
readlink(const char * path,char * buf,size_t bufsize)35*63eb84d1Schristos readlink (const char *path, char *buf, size_t bufsize)
36*63eb84d1Schristos {
37*63eb84d1Schristos struct stat statbuf;
38*63eb84d1Schristos
39*63eb84d1Schristos /* In general we should use lstat() here, not stat(). But on platforms
40*63eb84d1Schristos without symbolic links lstat() - if it exists - would be equivalent to
41*63eb84d1Schristos stat(), therefore we can use stat(). This saves us a configure check. */
42*63eb84d1Schristos if (stat (path, &statbuf) >= 0)
43*63eb84d1Schristos errno = EINVAL;
44*63eb84d1Schristos return -1;
45*63eb84d1Schristos }
46*63eb84d1Schristos
47*63eb84d1Schristos #endif
48