Browse Source

readlink: Use readlinkat if arch does not have the readlink syscall

Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Markos Chandras 11 years ago
parent
commit
e07db64b78
3 changed files with 10 additions and 0 deletions
  1. 1 0
      include/unistd.h
  2. 8 0
      libc/sysdeps/linux/common/readlink.c
  3. 1 0
      libc/sysdeps/linux/common/readlinkat.c

+ 1 - 0
include/unistd.h

@@ -914,6 +914,7 @@ extern int symlinkat (const char *__from, int __tofd,
 extern ssize_t readlinkat (int __fd, const char *__restrict __path,
 			   char *__restrict __buf, size_t __len)
      __THROW __nonnull ((2, 3)) __wur;
+libc_hidden_proto(readlinkat)
 #endif
 
 /* Remove the link NAME.  */

+ 8 - 0
libc/sysdeps/linux/common/readlink.c

@@ -10,5 +10,13 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#if defined(__NR_readlinkat) && !defined(__NR_readlink)
+# include <fcntl.h>
+ssize_t readlink (const char *path, char *buf, size_t len)
+{
+	return readlinkat(AT_FDCWD, path, buf, len);
+}
+#else
 _syscall3(ssize_t, readlink, const char *, path, char *, buf, size_t, bufsiz)
+#endif
 libc_hidden_def(readlink)

+ 1 - 0
libc/sysdeps/linux/common/readlinkat.c

@@ -11,6 +11,7 @@
 
 #ifdef __NR_readlinkat
 _syscall4(ssize_t, readlinkat, int, fd, const char *, path, char *, buf, size_t, len)
+libc_hidden_def(readlinkat)
 #else
 /* should add emulation with readlink() and /proc/self/fd/ ... */
 #endif