changeset 4408:84ab196c83d8

Provide the correct errno.
author Bruno Haible <bruno@clisp.org>
date Thu, 26 Jun 2003 11:03:35 +0000
parents 95a2013d54ed
children e107cd15c495
files lib/readlink.c
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/readlink.c
+++ b/lib/readlink.c
@@ -20,16 +20,28 @@
 #endif
 
 #include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #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;
 }