1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #ifndef _FCNTL_H
30 #define _FCNTL_H
31
32 #include <sys/cdefs.h>
33 #include <sys/types.h>
34 #include <linux/fadvise.h>
35 #include <linux/fcntl.h>
36 #include <linux/stat.h>
37 #include <linux/uio.h>
38
39 __BEGIN_DECLS
40
41 #ifdef __LP64__
42 /* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */
43 #define F_GETLK64 F_GETLK
44 #define F_SETLK64 F_SETLK
45 #define F_SETLKW64 F_SETLKW
46 #endif
47
48 #define O_ASYNC FASYNC
49 #define O_RSYNC O_SYNC
50
51 #define SPLICE_F_MOVE 1
52 #define SPLICE_F_NONBLOCK 2
53 #define SPLICE_F_MORE 4
54 #define SPLICE_F_GIFT 8
55
56 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
57 #define SYNC_FILE_RANGE_WRITE 2
58 #define SYNC_FILE_RANGE_WAIT_AFTER 4
59
60 extern int creat(const char*, mode_t);
61 extern int creat64(const char*, mode_t);
62 extern int fcntl(int, int, ...);
63 extern int openat(int, const char*, int, ...);
64 extern int openat64(int, const char*, int, ...);
65 extern int open(const char*, int, ...);
66 extern int open64(const char*, int, ...);
67 extern ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int);
68 extern ssize_t tee(int, int, size_t, unsigned int);
69 extern int unlinkat(int, const char*, int);
70 extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
71
72 #if defined(__USE_FILE_OFFSET64)
73 extern int fallocate(int, int, off_t, off_t) __RENAME(fallocate64);
74 extern int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64);
75 extern int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate);
76 #else
77 extern int fallocate(int, int, off_t, off_t);
78 extern int posix_fadvise(int, off_t, off_t, int);
79 extern int posix_fallocate(int, off_t, off_t);
80 #endif
81 extern int fallocate64(int, int, off64_t, off64_t);
82 extern int posix_fadvise64(int, off64_t, off64_t, int);
83 extern int posix_fallocate64(int, off64_t, off64_t);
84
85 extern int __open_2(const char*, int);
86 extern int __open_real(const char*, int, ...) __RENAME(open);
87 extern int __openat_2(int, const char*, int);
88 extern int __openat_real(int, const char*, int, ...) __RENAME(openat);
89 __errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
90 __errordecl(__creat_too_many_args, "too many arguments");
91
92 #if defined(__BIONIC_FORTIFY)
93
94 #if !defined(__clang__)
95
96 __BIONIC_FORTIFY_INLINE
open(const char * pathname,int flags,...)97 int open(const char* pathname, int flags, ...) {
98 if (__builtin_constant_p(flags)) {
99 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
100 __creat_missing_mode(); // compile time error
101 }
102 }
103
104 if (__builtin_va_arg_pack_len() > 1) {
105 __creat_too_many_args(); // compile time error
106 }
107
108 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
109 return __open_2(pathname, flags);
110 }
111
112 return __open_real(pathname, flags, __builtin_va_arg_pack());
113 }
114
115 __BIONIC_FORTIFY_INLINE
openat(int dirfd,const char * pathname,int flags,...)116 int openat(int dirfd, const char* pathname, int flags, ...) {
117 if (__builtin_constant_p(flags)) {
118 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
119 __creat_missing_mode(); // compile time error
120 }
121 }
122
123 if (__builtin_va_arg_pack_len() > 1) {
124 __creat_too_many_args(); // compile time error
125 }
126
127 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
128 return __openat_2(dirfd, pathname, flags);
129 }
130
131 return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack());
132 }
133
134 #endif /* !defined(__clang__) */
135
136 #endif /* defined(__BIONIC_FORTIFY) */
137
138 __END_DECLS
139
140 #endif /* _FCNTL_H */
141