1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <stdarg.h>
4
5 /*
6 * Although these definitions are called *_PORTABLE
7 * they are actually the ARM definitions
8 */
9
10 /* Derived from development/ndk/platforms/android-3/arch-arm/include/asm/fcntl.h */
11 /* NB x86 does not have these and only uses the generic definitions */
12 #define O_DIRECTORY_PORTABLE 040000
13 #define O_NOFOLLOW_PORTABLE 0100000
14 #define O_DIRECT_PORTABLE 0200000
15 #define O_LARGEFILE_PORTABLE 0400000
16
17 /* Derived from development/ndk/platforms/android-3/include/asm-generic/fcntl.h */
18 #define O_ACCMODE_PORTABLE 00000003
19 #define O_RDONLY_PORTABLE 00000000
20 #define O_WRONLY_PORTABLE 00000001
21 #define O_RDWR_PORTABLE 00000002
22 #ifndef O_CREAT_PORTABLE
23 #define O_CREAT_PORTABLE 00000100
24 #endif
25 #ifndef O_EXCL_PORTABLE
26 #define O_EXCL_PORTABLE 00000200
27 #endif
28 #ifndef O_NOCTTY_PORTABLE
29 #define O_NOCTTY_PORTABLE 00000400
30 #endif
31 #ifndef O_TRUNC_PORTABLE
32 #define O_TRUNC_PORTABLE 00001000
33 #endif
34 #ifndef O_APPEND_PORTABLE
35 #define O_APPEND_PORTABLE 00002000
36 #endif
37 #ifndef O_NONBLOCK_PORTABLE
38 #define O_NONBLOCK_PORTABLE 00004000
39 #endif
40 #ifndef O_SYNC_PORTABLE
41 #define O_SYNC_PORTABLE 00010000
42 #endif
43 #ifndef FASYNC_PORTABLE
44 #define FASYNC_PORTABLE 00020000
45 #endif
46 #ifndef O_DIRECT_PORTABLE
47 #define O_DIRECT_PORTABLE 00040000
48 #endif
49 #ifndef O_LARGEFILE_PORTABLE
50 #define O_LARGEFILE_PORTABLE 00100000
51 #endif
52 #ifndef O_DIRECTORY_PORTABLE
53 #define O_DIRECTORY_PORTABLE 00200000
54 #endif
55 #ifndef O_NOFOLLOW_PORTABLE
56 #define O_NOFOLLOW_PORTABLE 00400000
57 #endif
58 #ifndef O_NOATIME_PORTABLE
59 #define O_NOATIME_PORTABLE 01000000
60 #endif
61 #ifndef O_NDELAY_PORTABLE
62 #define O_NDELAY_PORTABLE O_NONBLOCK_PORTABLE
63 #endif
64
65 #if O_CREAT_PORTABLE==O_CREAT
66 #error Bad build environment
67 #endif
68
mips_change_flags(int flags)69 static inline int mips_change_flags(int flags)
70 {
71 int mipsflags = flags & O_ACCMODE_PORTABLE;
72 if (flags & O_CREAT_PORTABLE)
73 mipsflags |= O_CREAT;
74 if (flags & O_EXCL_PORTABLE)
75 mipsflags |= O_EXCL;
76 if (flags & O_NOCTTY_PORTABLE)
77 mipsflags |= O_NOCTTY;
78 if (flags & O_TRUNC_PORTABLE)
79 mipsflags |= O_TRUNC;
80 if (flags & O_APPEND_PORTABLE)
81 mipsflags |= O_APPEND;
82 if (flags & O_NONBLOCK_PORTABLE)
83 mipsflags |= O_NONBLOCK;
84 if (flags & O_SYNC_PORTABLE)
85 mipsflags |= O_SYNC;
86 if (flags & FASYNC_PORTABLE)
87 mipsflags |= FASYNC;
88 if (flags & O_DIRECT_PORTABLE)
89 mipsflags |= O_DIRECT;
90 if (flags & O_LARGEFILE_PORTABLE)
91 mipsflags |= O_LARGEFILE;
92 if (flags & O_DIRECTORY_PORTABLE)
93 mipsflags |= O_DIRECTORY;
94 if (flags & O_NOFOLLOW_PORTABLE)
95 mipsflags |= O_NOFOLLOW;
96 if (flags & O_NOATIME_PORTABLE)
97 mipsflags |= O_NOATIME;
98 if (flags & O_NDELAY_PORTABLE)
99 mipsflags |= O_NDELAY;
100
101 return mipsflags;
102 }
103
104 extern int __open(const char*, int, int);
open(const char * pathname,int flags,...)105 int open(const char *pathname, int flags, ...)
106 {
107 mode_t mode = 0;
108 flags |= O_LARGEFILE;
109
110 if (flags & O_CREAT)
111 {
112 va_list args;
113
114 va_start(args, flags);
115 mode = (mode_t) va_arg(args, int);
116 va_end(args);
117 }
118
119 return __open(pathname, mips_change_flags(flags), mode);
120 }
121