Browse Source

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

+ 1 - 0
include/sys/stat.h

@@ -335,6 +335,7 @@ libc_hidden_proto(mkdir)
    with FD.  */
 extern int mkdirat (int __fd, const char *__path, __mode_t __mode)
      __THROW __nonnull ((2));
+libc_hidden_proto(mkdirat)
 #endif
 
 /* Create a device file named PATH, with permission and special bits MODE

+ 9 - 1
libc/sysdeps/linux/common/mkdir.c

@@ -10,8 +10,15 @@
 #include <sys/syscall.h>
 #include <sys/stat.h>
 
+#if defined __NR_mkdirat && !defined __NR_mkdir
+# include <fcntl.h>
+int mkdir(const char *pathname, mode_t mode)
+{
+	return mkdirat(AT_FDCWD, pathname, mode);
+}
 
-#define __NR___syscall_mkdir __NR_mkdir
+#else
+# define __NR___syscall_mkdir __NR_mkdir
 static __inline__ _syscall2(int, __syscall_mkdir, const char *, pathname,
 		__kernel_mode_t, mode)
 
@@ -19,4 +26,5 @@ int mkdir(const char *pathname, mode_t mode)
 {
 	return (__syscall_mkdir(pathname, mode));
 }
+#endif
 libc_hidden_def(mkdir)

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

@@ -11,6 +11,7 @@
 
 #ifdef __NR_mkdirat
 _syscall3(int, mkdirat, int, fd, const char *, path, mode_t, mode)
+libc_hidden_def(mkdirat)
 #else
 /* should add emulation with mkdir() and /proc/self/fd/ ... */
 #endif