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