diff options
author | Shih-wei Liao <sliao@google.com> | 2012-02-05 23:52:46 -0800 |
---|---|---|
committer | Shih-wei Liao <sliao@google.com> | 2012-02-05 23:52:46 -0800 |
commit | 77401247ea8c15ae4ac022936731b83b2def1e9e (patch) | |
tree | 2663de3772571b20b4e730b5b0efce60685f9faa | |
parent | 4a0f056e6e94fe257cf9e503ccacbbc6bf598218 (diff) | |
download | gdk-77401247ea8c15ae4ac022936731b83b2def1e9e.tar.gz |
Finish open implementation
Change-Id: Ifa4ee3bcc3f590edcaf6a570c2cbb5c7b91584ca
-rw-r--r-- | headers/include/fcntl.h | 5 | ||||
-rw-r--r-- | libportable/arch-mips/open.c | 110 |
2 files changed, 103 insertions, 12 deletions
diff --git a/headers/include/fcntl.h b/headers/include/fcntl.h index 7219dd7..a452db3 100644 --- a/headers/include/fcntl.h +++ b/headers/include/fcntl.h @@ -43,7 +43,12 @@ __BEGIN_DECLS #define O_CLOEXEC 02000000 #endif +<<<<<<< current extern int open(const char* path, int mode, ...); +======= +extern int open_portable(const char* path, int mode, ...); +#define open open_portable +>>>>>>> patched extern int openat(int fd, const char* path, int mode, ...); extern int unlinkat(int dirfd, const char *pathname, int flags); extern int fcntl(int fd, int command, ...); diff --git a/libportable/arch-mips/open.c b/libportable/arch-mips/open.c index 6dd5a8c..aa3ac79 100644 --- a/libportable/arch-mips/open.c +++ b/libportable/arch-mips/open.c @@ -2,27 +2,113 @@ #include <fcntl.h> #include <stdarg.h> -extern int __open(const char*, int, int); -#define O_CREAT_PORTABLE 00000100 +/* + * Although these definitions are called *_PORTABLE + * they are actually the ARM definitions + */ + +/* Derived from development/ndk/platforms/android-3/arch-arm/include/asm/fcntl.h */ +/* NB x86 does not have these and only uses the generic definitions */ +#define O_DIRECTORY_PORTABLE 040000 +#define O_NOFOLLOW_PORTABLE 0100000 +#define O_DIRECT_PORTABLE 0200000 +#define O_LARGEFILE_PORTABLE 0400000 + +/* Derived from development/ndk/platforms/android-3/include/asm-generic/fcntl.h */ +#define O_ACCMODE_PORTABLE 00000003 +#define O_RDONLY_PORTABLE 00000000 +#define O_WRONLY_PORTABLE 00000001 +#define O_RDWR_PORTABLE 00000002 +#ifndef O_CREAT_PORTABLE +#define O_CREAT_PORTABLE 00000100 +#endif +#ifndef O_EXCL_PORTABLE +#define O_EXCL_PORTABLE 00000200 +#endif +#ifndef O_NOCTTY_PORTABLE +#define O_NOCTTY_PORTABLE 00000400 +#endif +#ifndef O_TRUNC_PORTABLE +#define O_TRUNC_PORTABLE 00001000 +#endif +#ifndef O_APPEND_PORTABLE +#define O_APPEND_PORTABLE 00002000 +#endif +#ifndef O_NONBLOCK_PORTABLE +#define O_NONBLOCK_PORTABLE 00004000 +#endif +#ifndef O_SYNC_PORTABLE +#define O_SYNC_PORTABLE 00010000 +#endif +#ifndef FASYNC_PORTABLE +#define FASYNC_PORTABLE 00020000 +#endif +#ifndef O_DIRECT_PORTABLE +#define O_DIRECT_PORTABLE 00040000 +#endif +#ifndef O_LARGEFILE_PORTABLE +#define O_LARGEFILE_PORTABLE 00100000 +#endif +#ifndef O_DIRECTORY_PORTABLE +#define O_DIRECTORY_PORTABLE 00200000 +#endif +#ifndef O_NOFOLLOW_PORTABLE +#define O_NOFOLLOW_PORTABLE 00400000 +#endif +#ifndef O_NOATIME_PORTABLE +#define O_NOATIME_PORTABLE 01000000 +#endif +#ifndef O_NDELAY_PORTABLE +#define O_NDELAY_PORTABLE O_NONBLOCK_PORTABLE +#endif #if O_CREAT_PORTABLE==O_CREAT #error Bad build environment #endif -static inline int mips_change_flags(int flags) { - if (flags & O_CREAT_PORTABLE) { - flags &= ~O_CREAT_PORTABLE; - flags |= O_CREAT; - } - return flags; +static inline int mips_change_flags(int flags) +{ + int mipsflags = flags & O_ACCMODE_PORTABLE; + if (flags & O_CREAT_PORTABLE) + mipsflags |= O_CREAT; + if (flags & O_EXCL_PORTABLE) + mipsflags |= O_EXCL; + if (flags & O_NOCTTY_PORTABLE) + mipsflags |= O_NOCTTY; + if (flags & O_TRUNC_PORTABLE) + mipsflags |= O_TRUNC; + if (flags & O_APPEND_PORTABLE) + mipsflags |= O_APPEND; + if (flags & O_NONBLOCK_PORTABLE) + mipsflags |= O_NONBLOCK; + if (flags & O_SYNC_PORTABLE) + mipsflags |= O_SYNC; + if (flags & FASYNC_PORTABLE) + mipsflags |= FASYNC; + if (flags & O_DIRECT_PORTABLE) + mipsflags |= O_DIRECT; + if (flags & O_LARGEFILE_PORTABLE) + mipsflags |= O_LARGEFILE; + if (flags & O_DIRECTORY_PORTABLE) + mipsflags |= O_DIRECTORY; + if (flags & O_NOFOLLOW_PORTABLE) + mipsflags |= O_NOFOLLOW; + if (flags & O_NOATIME_PORTABLE) + mipsflags |= O_NOATIME; + if (flags & O_NDELAY_PORTABLE) + mipsflags |= O_NDELAY; + + return mipsflags; } -int open(const char *pathname, int flags, ...) { +extern int __open(const char*, int, int); +int open_portable(const char *pathname, int flags, ...) +{ mode_t mode = 0; - flags = mips_change_flags(flags); flags |= O_LARGEFILE; - if (flags & O_CREAT) { + if (flags & O_CREAT) + { va_list args; va_start(args, flags); @@ -30,5 +116,5 @@ int open(const char *pathname, int flags, ...) { va_end(args); } - return __open(pathname, flags, mode); + return __open(pathname, mips_change_flags(flags), mode); } |