Browse Source

unlink: Use unlinkat if arch does not have the unlink 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
09a387a0fc
3 changed files with 10 additions and 0 deletions
  1. 1 0
      include/unistd.h
  2. 8 0
      libc/sysdeps/linux/common/unlink.c
  3. 1 0
      libc/sysdeps/linux/common/unlinkat.c

+ 1 - 0
include/unistd.h

@@ -923,6 +923,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.  */

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

@@ -10,5 +10,13 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#if defined __NR_unlinkat && !defined __NR_unlink
+# include <fcntl.h>
+int unlink(const char *pathname)
+{
+	return unlinkat(AT_FDCWD, pathname, 0);
+}
+#else
 _syscall1(int, unlink, const char *, pathname)
+#endif
 libc_hidden_def(unlink)

+ 1 - 0
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