blob: c49dbd07ae738c34a830234eda38ff32c2a097ff [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 */
Elliott Hughese9893992013-10-17 11:45:22 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _FCNTL_H
30#define _FCNTL_H
31
32#include <sys/cdefs.h>
33#include <sys/types.h>
Elliott Hughes01e505a2014-01-07 17:47:20 -080034#include <linux/fadvise.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#include <linux/fcntl.h>
Elliott Hughes64d83822014-12-29 11:14:38 -080036#include <linux/stat.h>
Elliott Hughes3f525d42014-06-24 16:32:01 -070037#include <linux/uio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
Josh Gaoee8d1692016-04-07 14:16:30 -070039#include <bits/fcntl.h>
Elliott Hughesfd936ae2016-08-12 10:16:34 -070040#include <bits/seek_constants.h>
Josh Gaoee8d1692016-04-07 14:16:30 -070041
Elliott Hughes5704c422016-01-25 18:06:24 -080042#if defined(__USE_GNU) || defined(__USE_BSD)
43#include <bits/lockf.h>
44#endif
45
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046__BEGIN_DECLS
47
Serban Constantinescu48501af2014-03-14 13:16:25 +000048#ifdef __LP64__
Christopher Ferrisba8d4f42014-09-03 19:56:49 -070049/* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */
Serban Constantinescu48501af2014-03-14 13:16:25 +000050#define F_GETLK64 F_GETLK
51#define F_SETLK64 F_SETLK
52#define F_SETLKW64 F_SETLKW
53#endif
54
Elliott Hughes3f525d42014-06-24 16:32:01 -070055#define O_ASYNC FASYNC
Elliott Hughes31165ed2014-09-23 17:34:29 -070056#define O_RSYNC O_SYNC
Elliott Hughes3f525d42014-06-24 16:32:01 -070057
58#define SPLICE_F_MOVE 1
59#define SPLICE_F_NONBLOCK 2
60#define SPLICE_F_MORE 4
61#define SPLICE_F_GIFT 8
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
Elliott Hughes34347272014-02-26 11:10:32 -080063#define SYNC_FILE_RANGE_WAIT_BEFORE 1
64#define SYNC_FILE_RANGE_WRITE 2
65#define SYNC_FILE_RANGE_WAIT_AFTER 4
66
Elliott Hughes3b2096a2016-07-22 18:57:12 -070067int creat(const char*, mode_t);
68int creat64(const char*, mode_t) __INTRODUCED_IN(21);
69int openat(int, const char*, int, ...);
70int openat64(int, const char*, int, ...) __INTRODUCED_IN(21);
71int open(const char*, int, ...);
72int open64(const char*, int, ...) __INTRODUCED_IN(21);
73ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int) __INTRODUCED_IN(21);
74ssize_t tee(int, int, size_t, unsigned int) __INTRODUCED_IN(21);
75ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int) __INTRODUCED_IN(21);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080076
Elliott Hughes68dc20d2015-02-06 22:28:49 -080077#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -070078int fallocate(int, int, off_t, off_t) __RENAME(fallocate64) __INTRODUCED_IN(21);
79int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64) __INTRODUCED_IN(21);
80int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate) __INTRODUCED_IN(21);
Elliott Hughes68dc20d2015-02-06 22:28:49 -080081#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -070082int fallocate(int, int, off_t, off_t) __INTRODUCED_IN(21);
83int posix_fadvise(int, off_t, off_t, int) __INTRODUCED_IN(21);
84int posix_fallocate(int, off_t, off_t) __INTRODUCED_IN(21);
Elliott Hughes68dc20d2015-02-06 22:28:49 -080085#endif
Elliott Hughes3b2096a2016-07-22 18:57:12 -070086int fallocate64(int, int, off64_t, off64_t) __INTRODUCED_IN(21);
87int posix_fadvise64(int, off64_t, off64_t, int) __INTRODUCED_IN(21);
88int posix_fallocate64(int, off64_t, off64_t) __INTRODUCED_IN(21);
Elliott Hughes68dc20d2015-02-06 22:28:49 -080089
Elliott Hughes55147ad2016-04-05 11:06:02 -070090#if defined(__USE_GNU)
Josh Gao46b44162016-05-27 11:14:16 -070091ssize_t readahead(int, off64_t, size_t) __INTRODUCED_IN(16);
Josh Gao34c599a2016-04-29 13:45:25 -070092int sync_file_range(int, off64_t, off64_t, unsigned int) __INTRODUCED_IN_FUTURE;
Elliott Hughes55147ad2016-04-05 11:06:02 -070093#endif
94
Elliott Hughes3b2096a2016-07-22 18:57:12 -070095int __open_2(const char*, int) __INTRODUCED_IN(17);
96int __open_real(const char*, int, ...) __RENAME(open);
97int __openat_2(int, const char*, int) __INTRODUCED_IN(17);
98int __openat_real(int, const char*, int, ...) __RENAME(openat);
Nick Kralevicha641c182013-06-18 13:07:18 -070099__errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
100__errordecl(__creat_too_many_args, "too many arguments");
Elliott Hughescd0609f2013-12-19 12:21:07 -0800101
Dan Albert658727e2014-10-07 11:10:36 -0700102#if defined(__BIONIC_FORTIFY)
103
Elliott Hughescd0609f2013-12-19 12:21:07 -0800104#if !defined(__clang__)
Nick Kralevich8118f622012-06-26 15:08:06 -0700105
106__BIONIC_FORTIFY_INLINE
Elliott Hughescd0609f2013-12-19 12:21:07 -0800107int open(const char* pathname, int flags, ...) {
Nick Kralevich8118f622012-06-26 15:08:06 -0700108 if (__builtin_constant_p(flags)) {
109 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700110 __creat_missing_mode(); /* Compile time error. */
Nick Kralevich8118f622012-06-26 15:08:06 -0700111 }
112 }
113
114 if (__builtin_va_arg_pack_len() > 1) {
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700115 __creat_too_many_args(); /* Compile time error. */
Nick Kralevich8118f622012-06-26 15:08:06 -0700116 }
117
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700118 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
Nick Kralevich8118f622012-06-26 15:08:06 -0700119 return __open_2(pathname, flags);
120 }
121
122 return __open_real(pathname, flags, __builtin_va_arg_pack());
123}
124
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700125__BIONIC_FORTIFY_INLINE
Elliott Hughescd0609f2013-12-19 12:21:07 -0800126int openat(int dirfd, const char* pathname, int flags, ...) {
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700127 if (__builtin_constant_p(flags)) {
128 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700129 __creat_missing_mode(); /* Compile time error. */
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700130 }
131 }
132
133 if (__builtin_va_arg_pack_len() > 1) {
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700134 __creat_too_many_args(); /* Compile time error. */
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700135 }
136
137 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
138 return __openat_2(dirfd, pathname, flags);
139 }
140
141 return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack());
142}
143
Elliott Hughescd0609f2013-12-19 12:21:07 -0800144#endif /* !defined(__clang__) */
145
146#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevich8118f622012-06-26 15:08:06 -0700147
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800148__END_DECLS
149
150#endif /* _FCNTL_H */