[PATCH v2 13/46] rename: Use renameat if arch does not have the rename syscall
Markos Chandras
markos.chandras at gmail.com
Mon Nov 26 14:23:55 UTC 2012
From: Markos Chandras <markos.chandras at imgtec.com>
Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
include/stdio.h | 1 +
libc/sysdeps/linux/common/rename.c | 9 ++++++++-
libc/sysdeps/linux/common/renameat.c | 1 +
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/stdio.h b/include/stdio.h
index 289b861..c531d88 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -152,6 +152,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
diff --git a/libc/sysdeps/linux/common/rename.c b/libc/sysdeps/linux/common/rename.c
index 9d8397a..bc4ea6f 100644
--- a/libc/sysdeps/linux/common/rename.c
+++ b/libc/sysdeps/linux/common/rename.c
@@ -8,11 +8,18 @@
*/
#include <sys/syscall.h>
+#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
#include <stdio.h>
+#if defined(__NR_renameat) && !defined(__NR_rename)
+int rename(const char *oldpath, const char *newpath)
+{
+ return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
+}
+#else
#define __NR___syscall_rename __NR_rename
static __inline__ _syscall2(int, __syscall_rename, const char *, oldpath,
const char *, newpath)
@@ -21,4 +28,4 @@ int rename(const char * oldpath, const char * newpath)
{
return __syscall_rename(oldpath, newpath);
}
-
+#endif
diff --git a/libc/sysdeps/linux/common/renameat.c b/libc/sysdeps/linux/common/renameat.c
index a898f7b..b0b91fa 100644
--- a/libc/sysdeps/linux/common/renameat.c
+++ b/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
--
1.8.0
More information about the uClibc
mailing list