X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Freadlink.c;h=c264efd8c8da994ae3a92f82546d07df02689c2e;hb=8518213783139778cd7effa5e6f2de8f81e215a0;hp=72d0e04475de401cc67f5d2f0e3a410511c5fcca;hpb=84645eae86ddff86ca4760ca71b4852673dedd03;p=gnulib.git diff --git a/lib/readlink.c b/lib/readlink.c index 72d0e0447..c264efd8c 100644 --- a/lib/readlink.c +++ b/lib/readlink.c @@ -20,16 +20,28 @@ #endif #include +#include +#include #if !HAVE_READLINK /* readlink() substitute for systems that don't have a readlink() function, such as DJGPP 2.03 and mingw32. */ +/* The official POSIX return type of readlink() is ssize_t, but since here + we have no declaration in a public header file, we use 'int' as return + type. */ + int -readlink (const char *filename, char *buffer, size_t bufsize) +readlink (const char *path, char *buf, size_t bufsize) { - errno = EINVAL; + struct stat statbuf; + + /* In general we should use lstat() here, not stat(). But on platforms + without symbolic links lstat() - if it exists - would be equivalent to + stat(), therefore we can use stat(). This saves us a configure check. */ + if (stat (path, &statbuf) >= 0) + errno = EINVAL; return -1; }