[PATCH v2 07/46] unlink: Use unlinkat if arch does not have the unlink syscall
Markos Chandras
markos.chandras at gmail.com
Mon Nov 26 14:23:49 UTC 2012
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/unlink.c | 8 ++++++++
libc/sysdeps/linux/common/unlinkat.c | 1 +
3 files changed, 10 insertions(+)
diff --git a/include/unistd.h b/include/unistd.h
index ee08e19..e58945d 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -859,6 +859,7 @@ libc_hidden_proto(unlink)
/* Remove the link NAME relative to FD. */
extern int unlinkat (int __fd, __const char *__name, int __flag)
__THROW __nonnull ((2));
+libc_hidden_proto(unlinkat)
#endif
/* Remove the directory PATH. */
diff --git a/libc/sysdeps/linux/common/unlink.c b/libc/sysdeps/linux/common/unlink.c
index 513cdd5..6ece291 100644
--- a/libc/sysdeps/linux/common/unlink.c
+++ b/libc/sysdeps/linux/common/unlink.c
@@ -8,8 +8,16 @@
*/
#include <sys/syscall.h>
+#include <fcntl.h>
#include <unistd.h>
+#if defined(__NR_unlinkat) && !defined(__NR_unlink)
+int unlink(const char *pathname)
+{
+ return unlinkat(AT_FDCWD, pathname, 0);
+}
+#else
_syscall1(int, unlink, const char *, pathname)
+#endif
libc_hidden_def(unlink)
diff --git a/libc/sysdeps/linux/common/unlinkat.c b/libc/sysdeps/linux/common/unlinkat.c
index 0eaf2b6..432af1b 100644
--- a/libc/sysdeps/linux/common/unlinkat.c
+++ b/libc/sysdeps/linux/common/unlinkat.c
@@ -11,6 +11,7 @@
#ifdef __NR_unlinkat
_syscall3(int, unlinkat, int, fd, const char *, file, int, flag)
+libc_hidden_def(unlinkat)
#else
/* should add emulation with unlink() and /proc/self/fd/ ... */
#endif
--
1.8.0
More information about the uClibc
mailing list