[PATCH v2 09/46] chown: Use fchownat if arch does not have the chown syscall
Markos Chandras
markos.chandras at gmail.com
Mon Nov 26 14:23:51 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/chown.c | 9 +++++++++
libc/sysdeps/linux/common/fchownat.c | 1 +
3 files changed, 11 insertions(+)
diff --git a/include/unistd.h b/include/unistd.h
index e58945d..296ae0a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -469,6 +469,7 @@ extern int lchown (__const char *__file, __uid_t __owner, __gid_t __group)
extern int fchownat (int __fd, __const char *__file, __uid_t __owner,
__gid_t __group, int __flag)
__THROW __nonnull ((2)) __wur;
+libc_hidden_proto(fchownat)
#endif /* Use GNU. */
/* Change the process's working directory to PATH. */
diff --git a/libc/sysdeps/linux/common/chown.c b/libc/sysdeps/linux/common/chown.c
index f2c60e0..edca3f8 100644
--- a/libc/sysdeps/linux/common/chown.c
+++ b/libc/sysdeps/linux/common/chown.c
@@ -8,9 +8,17 @@
*/
#include <sys/syscall.h>
+#include <fcntl.h>
#include <unistd.h>
#include <bits/wordsize.h>
+#if defined(__NR_fchownat) && !defined(__NR_chown)
+int chown(const char *path, uid_t owner, gid_t group)
+{
+ return fchownat(AT_FDCWD, path, owner, group, 0);
+}
+
+#else
#if (__WORDSIZE == 32 && defined(__NR_chown32)) || __WORDSIZE == 64
# ifdef __NR_chown32
@@ -37,4 +45,5 @@ int chown(const char *path, uid_t owner, gid_t group)
}
#endif
+#endif
libc_hidden_def(chown)
diff --git a/libc/sysdeps/linux/common/fchownat.c b/libc/sysdeps/linux/common/fchownat.c
index 707164d..4ad818b 100644
--- a/libc/sysdeps/linux/common/fchownat.c
+++ b/libc/sysdeps/linux/common/fchownat.c
@@ -11,6 +11,7 @@
#ifdef __NR_fchownat
_syscall5(int, fchownat, int, fd, const char *, file, uid_t, owner, gid_t, group, int, flag)
+libc_hidden_def(fchownat)
#else
/* should add emulation with fchown() and /proc/self/fd/ ... */
#endif
--
1.8.0
More information about the uClibc
mailing list