blob: db56ce3cabc28da7771d62a43b27e0a1d5cf302f [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 Hughes3f525d42014-06-24 16:32:01 -070036#include <linux/uio.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037#include <unistd.h> /* this is not required, but makes client code much happier */
38
39__BEGIN_DECLS
40
Serban Constantinescu48501af2014-03-14 13:16:25 +000041#ifdef __LP64__
Christopher Ferrisba8d4f42014-09-03 19:56:49 -070042/* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */
Serban Constantinescu48501af2014-03-14 13:16:25 +000043#define F_GETLK64 F_GETLK
44#define F_SETLK64 F_SETLK
45#define F_SETLKW64 F_SETLKW
46#endif
47
Elliott Hughes3f525d42014-06-24 16:32:01 -070048#define O_ASYNC FASYNC
49
50#define SPLICE_F_MOVE 1
51#define SPLICE_F_NONBLOCK 2
52#define SPLICE_F_MORE 4
53#define SPLICE_F_GIFT 8
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054
Elliott Hughes34347272014-02-26 11:10:32 -080055#define SYNC_FILE_RANGE_WAIT_BEFORE 1
56#define SYNC_FILE_RANGE_WRITE 2
57#define SYNC_FILE_RANGE_WAIT_AFTER 4
58
Elliott Hughesf64b8ea2014-02-03 16:20:46 -080059extern int creat(const char*, mode_t);
Elliott Hughesdb1ea342014-01-17 18:42:49 -080060extern int creat64(const char*, mode_t);
Elliott Hughesf64b8ea2014-02-03 16:20:46 -080061extern int fallocate64(int, int, off64_t, off64_t);
62extern int fallocate(int, int, off_t, off_t);
63extern int fcntl(int, int, ...);
64extern int openat(int, const char*, int, ...);
Elliott Hughesdb1ea342014-01-17 18:42:49 -080065extern int openat64(int, const char*, int, ...);
Elliott Hughesf64b8ea2014-02-03 16:20:46 -080066extern int open(const char*, int, ...);
Elliott Hughesdb1ea342014-01-17 18:42:49 -080067extern int open64(const char*, int, ...);
Elliott Hughesb587f332014-09-10 17:39:00 -070068extern int posix_fadvise64(int, off64_t, off64_t, int);
69extern int posix_fadvise(int, off_t, off_t, int);
Elliott Hughesf64b8ea2014-02-03 16:20:46 -080070extern int posix_fallocate64(int, off64_t, off64_t);
71extern int posix_fallocate(int, off_t, off_t);
Elliott Hughes3f525d42014-06-24 16:32:01 -070072extern ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int);
73extern ssize_t tee(int, int, size_t, unsigned int);
Elliott Hughesf64b8ea2014-02-03 16:20:46 -080074extern int unlinkat(int, const char*, int);
Elliott Hughes3f525d42014-06-24 16:32:01 -070075extern ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080076
Elliott Hughescd0609f2013-12-19 12:21:07 -080077#if defined(__BIONIC_FORTIFY)
78
79extern int __open_2(const char*, int);
Elliott Hughes2cfb4e82014-08-18 14:45:42 -070080extern int __open_real(const char*, int, ...) __RENAME(open);
Elliott Hughescd0609f2013-12-19 12:21:07 -080081extern int __openat_2(int, const char*, int);
Elliott Hughes2cfb4e82014-08-18 14:45:42 -070082extern int __openat_real(int, const char*, int, ...) __RENAME(openat);
Nick Kralevicha641c182013-06-18 13:07:18 -070083__errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
84__errordecl(__creat_too_many_args, "too many arguments");
Elliott Hughescd0609f2013-12-19 12:21:07 -080085
86#if !defined(__clang__)
Nick Kralevich8118f622012-06-26 15:08:06 -070087
88__BIONIC_FORTIFY_INLINE
Elliott Hughescd0609f2013-12-19 12:21:07 -080089int open(const char* pathname, int flags, ...) {
Nick Kralevich8118f622012-06-26 15:08:06 -070090 if (__builtin_constant_p(flags)) {
91 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Nick Kralevicha641c182013-06-18 13:07:18 -070092 __creat_missing_mode(); // compile time error
Nick Kralevich8118f622012-06-26 15:08:06 -070093 }
94 }
95
96 if (__builtin_va_arg_pack_len() > 1) {
Nick Kralevicha641c182013-06-18 13:07:18 -070097 __creat_too_many_args(); // compile time error
Nick Kralevich8118f622012-06-26 15:08:06 -070098 }
99
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700100 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
Nick Kralevich8118f622012-06-26 15:08:06 -0700101 return __open_2(pathname, flags);
102 }
103
104 return __open_real(pathname, flags, __builtin_va_arg_pack());
105}
106
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700107__BIONIC_FORTIFY_INLINE
Elliott Hughescd0609f2013-12-19 12:21:07 -0800108int openat(int dirfd, const char* pathname, int flags, ...) {
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700109 if (__builtin_constant_p(flags)) {
110 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700111 __creat_missing_mode(); // compile time error
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700112 }
113 }
114
115 if (__builtin_va_arg_pack_len() > 1) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700116 __creat_too_many_args(); // compile time error
Nick Kralevicha3e230d2012-07-02 12:24:42 -0700117 }
118
119 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
120 return __openat_2(dirfd, pathname, flags);
121 }
122
123 return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack());
124}
125
Elliott Hughescd0609f2013-12-19 12:21:07 -0800126#endif /* !defined(__clang__) */
127
128#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevich8118f622012-06-26 15:08:06 -0700129
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130__END_DECLS
131
132#endif /* _FCNTL_H */