[PATCH v2 12/46] mkdir: Use mkdirat if arch does not have the mkdir syscall

Markos Chandras markos.chandras at gmail.com
Mon Nov 26 14:23:54 UTC 2012


From: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 include/sys/stat.h                  | 1 +
 libc/sysdeps/linux/common/mkdir.c   | 8 ++++++++
 libc/sysdeps/linux/common/mkdirat.c | 1 +
 3 files changed, 10 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 88b7044..e04fd44 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -336,6 +336,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
diff --git a/libc/sysdeps/linux/common/mkdir.c b/libc/sysdeps/linux/common/mkdir.c
index fbc587d..933812b 100644
--- a/libc/sysdeps/linux/common/mkdir.c
+++ b/libc/sysdeps/linux/common/mkdir.c
@@ -9,8 +9,15 @@
 
 #include <sys/syscall.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 
+#if defined(__NR_mkdirat) && !defined(__NR_mkdir)
+int mkdir(const char *pathname, mode_t mode)
+{
+	return mkdirat(AT_FDCWD, pathname, mode);
+}
 
+#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)
diff --git a/libc/sysdeps/linux/common/mkdirat.c b/libc/sysdeps/linux/common/mkdirat.c
index 4da9468..871104b 100644
--- a/libc/sysdeps/linux/common/mkdirat.c
+++ b/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
-- 
1.8.0




More information about the uClibc mailing list