[git commit] symlink: Use symlinkat if arch does not have the symlink syscall

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Wed Feb 20 12:45:11 UTC 2013


commit: http://git.uclibc.org/uClibc/commit/?id=81b480369b905229c8dad41755c82aea0faca1e7
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

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

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 include/unistd.h                      |    1 +
 libc/sysdeps/linux/common/stubs.c     |    2 +-
 libc/sysdeps/linux/common/symlink.c   |   16 ++++++++++++++--
 libc/sysdeps/linux/common/symlinkat.c |    1 +
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h
index 175a582..8f2a09a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -909,6 +909,7 @@ libc_hidden_proto(readlink)
 /* Like symlink but a relative path in TO is interpreted relative to TOFD.  */
 extern int symlinkat (const char *__from, int __tofd,
 		      const char *__to) __THROW __nonnull ((1, 3)) __wur;
+libc_hidden_proto(symlinkat)
 
 /* Like readlink but a relative PATH is interpreted relative to FD.  */
 extern ssize_t readlinkat (int __fd, const char *__restrict __path,
diff --git a/libc/sysdeps/linux/common/stubs.c b/libc/sysdeps/linux/common/stubs.c
index 1fc2393..1f985e0 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -403,7 +403,7 @@ make_stub(swapoff)
 make_stub(swapon)
 #endif
 
-#ifndef __NR_symlink
+#if !defined __NR_symlink && !defined __NR_symlinkat
 make_stub(symlink)
 #endif
 
diff --git a/libc/sysdeps/linux/common/symlink.c b/libc/sysdeps/linux/common/symlink.c
index 15a576d..eee6e8f 100644
--- a/libc/sysdeps/linux/common/symlink.c
+++ b/libc/sysdeps/linux/common/symlink.c
@@ -8,8 +8,20 @@
  */
 
 #include <sys/syscall.h>
-
-#if defined __NR_symlink && (defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K)
+#if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K
 # include <unistd.h>
+
+# if defined __NR_symlinkat && !defined __NR_symlink
+#  include <fcntl.h>
+int symlink(const char *oldpath, const char *newpath)
+{
+	return symlinkat(oldpath, AT_FDCWD, newpath);
+}
+
+# elif defined(__NR_symlink)
+
 _syscall2(int, symlink, const char *, oldpath, const char *, newpath)
+
+# endif
+
 #endif
diff --git a/libc/sysdeps/linux/common/symlinkat.c b/libc/sysdeps/linux/common/symlinkat.c
index 6381b33..9181581 100644
--- a/libc/sysdeps/linux/common/symlinkat.c
+++ b/libc/sysdeps/linux/common/symlinkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_symlinkat
 _syscall3(int, symlinkat, const char *, from, int, tofd, const char *, to)
+libc_hidden_def(symlinkat)
 #else
 /* should add emulation with symlink() and /proc/self/fd/ ... */
 #endif


More information about the uClibc-cvs mailing list