blob: f41cbcc35c7dd4cd43233b7af328083b796a7e8b [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>
34#include <linux/fcntl.h>
35#include <unistd.h> /* this is not required, but makes client code much happier */
36
37__BEGIN_DECLS
38
39#ifndef O_ASYNC
40#define O_ASYNC FASYNC
41#endif
42
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080043extern int open(const char* path, int mode, ...);
44extern int openat(int fd, const char* path, int mode, ...);
45extern int unlinkat(int dirfd, const char *pathname, int flags);
46extern int fcntl(int fd, int command, ...);
47extern int creat(const char* path, mode_t mode);
48
Nick Kralevich16d1af12013-06-17 14:49:19 -070049#if defined(__BIONIC_FORTIFY) && !defined(__clang__)
Nick Kralevicha641c182013-06-18 13:07:18 -070050__errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
51__errordecl(__creat_too_many_args, "too many arguments");
Nick Kralevich8118f622012-06-26 15:08:06 -070052extern int __open_real(const char *pathname, int flags, ...)
53 __asm__(__USER_LABEL_PREFIX__ "open");
54extern int __open_2(const char *, int);
55
56__BIONIC_FORTIFY_INLINE
57int open(const char *pathname, int flags, ...) {
58 if (__builtin_constant_p(flags)) {
59 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Nick Kralevicha641c182013-06-18 13:07:18 -070060 __creat_missing_mode(); // compile time error
Nick Kralevich8118f622012-06-26 15:08:06 -070061 }
62 }
63
64 if (__builtin_va_arg_pack_len() > 1) {
Nick Kralevicha641c182013-06-18 13:07:18 -070065 __creat_too_many_args(); // compile time error
Nick Kralevich8118f622012-06-26 15:08:06 -070066 }
67
Nick Kralevicha3e230d2012-07-02 12:24:42 -070068 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
Nick Kralevich8118f622012-06-26 15:08:06 -070069 return __open_2(pathname, flags);
70 }
71
72 return __open_real(pathname, flags, __builtin_va_arg_pack());
73}
74
Nick Kralevicha3e230d2012-07-02 12:24:42 -070075extern int __openat_2(int, const char *, int);
76extern int __openat_real(int dirfd, const char *pathname, int flags, ...)
77 __asm__(__USER_LABEL_PREFIX__ "openat");
78
79__BIONIC_FORTIFY_INLINE
80int openat(int dirfd, const char *pathname, int flags, ...) {
81 if (__builtin_constant_p(flags)) {
82 if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) {
Nick Kralevicha641c182013-06-18 13:07:18 -070083 __creat_missing_mode(); // compile time error
Nick Kralevicha3e230d2012-07-02 12:24:42 -070084 }
85 }
86
87 if (__builtin_va_arg_pack_len() > 1) {
Nick Kralevicha641c182013-06-18 13:07:18 -070088 __creat_too_many_args(); // compile time error
Nick Kralevicha3e230d2012-07-02 12:24:42 -070089 }
90
91 if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) {
92 return __openat_2(dirfd, pathname, flags);
93 }
94
95 return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack());
96}
97
Nick Kralevich16d1af12013-06-17 14:49:19 -070098#endif /* defined(__BIONIC_FORTIFY) && !defined(__clang__) */
Nick Kralevich8118f622012-06-26 15:08:06 -070099
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800100__END_DECLS
101
102#endif /* _FCNTL_H */