Browse Source

chmod: Use fchmodat if arch does not have the chmod 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
82cab37865
3 changed files with 12 additions and 1 deletions
  1. 1 0
      include/sys/stat.h
  2. 10 1
      libc/sysdeps/linux/common/chmod.c
  3. 1 0
      libc/sysdeps/linux/common/fchmodat.c

+ 1 - 0
include/sys/stat.h

@@ -309,6 +309,7 @@ extern int fchmod (int __fd, __mode_t __mode) __THROW;
 extern int fchmodat (int __fd, const char *__file, __mode_t __mode,
 		     int __flag)
      __THROW __nonnull ((2)) __wur;
+libc_hidden_proto(fchmodat)
 #endif /* Use ATFILE.  */
 
 

+ 10 - 1
libc/sysdeps/linux/common/chmod.c

@@ -9,13 +9,22 @@
 
 #include <sys/syscall.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
+#if defined __NR_fchmodat && !defined __NR_chmod
+# include <fcntl.h>
+int chmod(const char *path, mode_t mode)
+{
+	return fchmodat(AT_FDCWD, path, mode, 0);
+}
 
-#define __NR___syscall_chmod __NR_chmod
+#else
+# define __NR___syscall_chmod __NR_chmod
 static __inline__ _syscall2(int, __syscall_chmod, const char *, path, __kernel_mode_t, mode)
 
 int chmod(const char *path, mode_t mode)
 {
 	return __syscall_chmod(path, mode);
 }
+#endif
 libc_hidden_def(chmod)

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

@@ -32,6 +32,7 @@ int fchmodat(int fd, const char *file, mode_t mode, int flag)
 
 	return INLINE_SYSCALL(fchmodat, 3, fd, file, mode);
 }
+libc_hidden_def(fchmodat)
 #else
 /* should add emulation with fchmod() and /proc/self/fd/ ... */
 #endif