The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | */ |
Elliott Hughes | e989399 | 2013-10-17 11:45:22 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _FCNTL_H |
| 30 | #define _FCNTL_H |
| 31 | |
| 32 | #include <sys/cdefs.h> |
| 33 | #include <sys/types.h> |
Elliott Hughes | 01e505a | 2014-01-07 17:47:20 -0800 | [diff] [blame] | 34 | #include <linux/fadvise.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #include <linux/fcntl.h> |
| 36 | #include <unistd.h> /* this is not required, but makes client code much happier */ |
| 37 | |
| 38 | __BEGIN_DECLS |
| 39 | |
| 40 | #ifndef O_ASYNC |
| 41 | #define O_ASYNC FASYNC |
| 42 | #endif |
| 43 | |
Elliott Hughes | f64b8ea | 2014-02-03 16:20:46 -0800 | [diff] [blame] | 44 | extern int creat(const char*, mode_t); |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame^] | 45 | extern int creat64(const char*, mode_t); |
Elliott Hughes | f64b8ea | 2014-02-03 16:20:46 -0800 | [diff] [blame] | 46 | extern int fallocate64(int, int, off64_t, off64_t); |
| 47 | extern int fallocate(int, int, off_t, off_t); |
| 48 | extern int fcntl(int, int, ...); |
| 49 | extern int openat(int, const char*, int, ...); |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame^] | 50 | extern int openat64(int, const char*, int, ...); |
Elliott Hughes | f64b8ea | 2014-02-03 16:20:46 -0800 | [diff] [blame] | 51 | extern int open(const char*, int, ...); |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame^] | 52 | extern int open64(const char*, int, ...); |
Elliott Hughes | f64b8ea | 2014-02-03 16:20:46 -0800 | [diff] [blame] | 53 | extern int posix_fallocate64(int, off64_t, off64_t); |
| 54 | extern int posix_fallocate(int, off_t, off_t); |
| 55 | extern int unlinkat(int, const char*, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 56 | |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 57 | #if defined(__BIONIC_FORTIFY) |
| 58 | |
| 59 | extern int __open_2(const char*, int); |
| 60 | extern int __open_real(const char*, int, ...) __asm__(__USER_LABEL_PREFIX__ "open"); |
| 61 | extern int __openat_2(int, const char*, int); |
| 62 | extern int __openat_real(int, const char*, int, ...) __asm__(__USER_LABEL_PREFIX__ "openat"); |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 63 | __errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode"); |
| 64 | __errordecl(__creat_too_many_args, "too many arguments"); |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 65 | |
| 66 | #if !defined(__clang__) |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 67 | |
| 68 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 69 | int open(const char* pathname, int flags, ...) { |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 70 | if (__builtin_constant_p(flags)) { |
| 71 | if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) { |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 72 | __creat_missing_mode(); // compile time error |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | if (__builtin_va_arg_pack_len() > 1) { |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 77 | __creat_too_many_args(); // compile time error |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 80 | if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) { |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 81 | return __open_2(pathname, flags); |
| 82 | } |
| 83 | |
| 84 | return __open_real(pathname, flags, __builtin_va_arg_pack()); |
| 85 | } |
| 86 | |
Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 87 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 88 | int openat(int dirfd, const char* pathname, int flags, ...) { |
Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 89 | if (__builtin_constant_p(flags)) { |
| 90 | if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) { |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 91 | __creat_missing_mode(); // compile time error |
Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | if (__builtin_va_arg_pack_len() > 1) { |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 96 | __creat_too_many_args(); // compile time error |
Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) { |
| 100 | return __openat_2(dirfd, pathname, flags); |
| 101 | } |
| 102 | |
| 103 | return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack()); |
| 104 | } |
| 105 | |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 106 | #endif /* !defined(__clang__) */ |
| 107 | |
| 108 | #endif /* defined(__BIONIC_FORTIFY) */ |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 109 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 110 | __END_DECLS |
| 111 | |
| 112 | #endif /* _FCNTL_H */ |