[PATCH v3 07/48] link: Use linkat if arch does not have the link syscall

Markos Chandras markos.chandras at gmail.com
Wed Jan 23 11:41:31 UTC 2013


From: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 include/unistd.h                   | 1 +
 libc/sysdeps/linux/common/link.c   | 9 +++++++++
 libc/sysdeps/linux/common/linkat.c | 1 +
 3 files changed, 11 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index e1169b4..58df21e 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -879,6 +879,7 @@ extern int link (const char *__from, const char *__to)
 extern int linkat (int __fromfd, const char *__from, int __tofd,
 		   const char *__to, int __flags)
      __THROW __nonnull ((2, 4)) __wur;
+libc_hidden_proto(linkat)
 #endif
 
 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
diff --git a/libc/sysdeps/linux/common/link.c b/libc/sysdeps/linux/common/link.c
index b5e5536..5856caa 100644
--- a/libc/sysdeps/linux/common/link.c
+++ b/libc/sysdeps/linux/common/link.c
@@ -8,5 +8,14 @@
  */
 
 #include <sys/syscall.h>
+#include <fcntl.h>
 #include <unistd.h>
+
+#if defined(__NR_linkat) && !defined(__NR_link)
+int link(const char *oldpath, const char *newpath)
+{
+	return linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
+}
+#else
 _syscall2(int, link, const char *, oldpath, const char *, newpath)
+#endif
diff --git a/libc/sysdeps/linux/common/linkat.c b/libc/sysdeps/linux/common/linkat.c
index 9abe9ec..26a3d08 100644
--- a/libc/sysdeps/linux/common/linkat.c
+++ b/libc/sysdeps/linux/common/linkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_linkat
 _syscall5(int, linkat, int, fromfd, const char *, from, int, tofd, const char *, to, int, flags)
+libc_hidden_def(linkat)
 #else
 /* should add emulation with link() and /proc/self/fd/ ... */
 #endif
-- 
1.8.1.1




More information about the uClibc mailing list