Browse Source

rename: Use renameat if arch does not have the rename 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
3a5be53a84
3 changed files with 11 additions and 0 deletions
  1. 1 0
      include/stdio.h
  2. 9 0
      libc/sysdeps/linux/common/rename.c
  3. 1 0
      libc/sysdeps/linux/common/renameat.c

+ 1 - 0
include/stdio.h

@@ -151,6 +151,7 @@ __END_NAMESPACE_STD
 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD.  */
 extern int renameat (int __oldfd, const char *__old, int __newfd,
 		     const char *__new) __THROW;
+libc_hidden_proto(renameat)
 #endif
 
 __BEGIN_NAMESPACE_STD

+ 9 - 0
libc/sysdeps/linux/common/rename.c

@@ -9,5 +9,14 @@
 
 #include <sys/syscall.h>
 #include <stdio.h>
+#include <unistd.h>
 
+#if defined __NR_renameat && !defined __NR_rename
+# include <fcntl.h>
+int rename(const char *oldpath, const char *newpath)
+{
+	return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
+}
+#else
 _syscall2(int, rename, const char *, oldpath, const char *, newpath)
+#endif

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

@@ -11,6 +11,7 @@
 
 #ifdef __NR_renameat
 _syscall4(int, renameat, int, oldfd, const char *, old, int, newfd, const char *, new)
+libc_hidden_def(renameat)
 #else
 /* should add emulation with rename() and /proc/self/fd/ ... */
 #endif