1 /*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <portability.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include <stdarg.h>
21 #include <fcntl_portable.h>
22
23
x86_change_flags(int flags)24 static inline int x86_change_flags(int flags)
25 {
26 int x86flags = flags & O_ACCMODE_PORTABLE;
27 if (flags & O_CREAT_PORTABLE)
28 x86flags |= O_CREAT;
29 if (flags & O_EXCL_PORTABLE)
30 x86flags |= O_EXCL;
31 if (flags & O_NOCTTY_PORTABLE)
32 x86flags |= O_NOCTTY;
33 if (flags & O_TRUNC_PORTABLE)
34 x86flags |= O_TRUNC;
35 if (flags & O_APPEND_PORTABLE)
36 x86flags |= O_APPEND;
37 if (flags & O_NONBLOCK_PORTABLE)
38 x86flags |= O_NONBLOCK;
39 if (flags & O_SYNC_PORTABLE)
40 x86flags |= O_SYNC;
41 if (flags & FASYNC_PORTABLE)
42 x86flags |= FASYNC;
43 if (flags & O_DIRECT_PORTABLE)
44 x86flags |= O_DIRECT;
45 if (flags & O_LARGEFILE_PORTABLE)
46 x86flags |= O_LARGEFILE;
47 if (flags & O_DIRECTORY_PORTABLE)
48 x86flags |= O_DIRECTORY;
49 if (flags & O_NOFOLLOW_PORTABLE)
50 x86flags |= O_NOFOLLOW;
51 if (flags & O_NOATIME_PORTABLE)
52 x86flags |= O_NOATIME;
53 if (flags & O_NDELAY_PORTABLE)
54 x86flags |= O_NDELAY;
55
56 return x86flags;
57 }
58
59 extern int __open(const char*, int, int);
WRAP(open)60 int WRAP(open)(const char *pathname, int flags, ...)
61 {
62 mode_t mode = 0;
63 flags |= O_LARGEFILE;
64
65 if (flags & O_CREAT)
66 {
67 va_list args;
68
69 va_start(args, flags);
70 mode = (mode_t) va_arg(args, int);
71 va_end(args);
72 }
73
74 return __open(pathname, x86_change_flags(flags), mode);
75 }
76