summaryrefslogtreecommitdiffstats
path: root/usr/klibc/open.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/open.c')
-rw-r--r--usr/klibc/open.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/usr/klibc/open.c b/usr/klibc/open.c
new file mode 100644
index 0000000..5305c3d
--- /dev/null
+++ b/usr/klibc/open.c
@@ -0,0 +1,47 @@
+/*
+ * open.c
+ *
+ * On 32-bit platforms we need to pass O_LARGEFILE to the open()
+ * system call, to indicate that we're 64-bit safe.
+ *
+ * For 64 bit systems without the open syscall, pass straight
+ * through into openat.
+ */
+
+#define _KLIBC_IN_OPEN_C
+#include <unistd.h>
+#include <fcntl.h>
+#include <bitsize.h>
+#include <sys/syscall.h>
+
+#ifndef __NR_open
+#if _BITSIZE == 32
+
+extern int __openat(int, const char *, int, mode_t);
+
+int open(const char *pathname, int flags, mode_t mode)
+{
+ return __openat(AT_FDCWD, pathname, flags | O_LARGEFILE, mode);
+}
+
+#else
+
+__extern int openat(int, const char *, int, ...);
+
+int open(const char *pathname, int flags, mode_t mode)
+{
+ return openat(AT_FDCWD, pathname, flags, mode);
+}
+
+#endif /* _BITSIZE == 32 */
+
+#elif _BITSIZE == 32 && !defined(__i386__) && !defined(__m68k__)
+
+extern int __open(const char *, int, mode_t);
+
+int open(const char *pathname, int flags, mode_t mode)
+{
+ return __open(pathname, flags | O_LARGEFILE, mode);
+}
+
+#endif /* __NR_open */