]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2005-2015 Free Software Foundation, Inc. |
4973cbe5 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
4973cbe5 UD |
17 | |
18 | #include <errno.h> | |
19 | #include <fcntl.h> | |
20 | #include <stdarg.h> | |
21 | #include <stddef.h> | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | #include <sys/stat.h> | |
25 | #include <sysdep-cancel.h> | |
d369ad76 | 26 | #include <not-cancel.h> |
4973cbe5 UD |
27 | |
28 | ||
3997b7c4 | 29 | #ifndef OPENAT |
4973cbe5 | 30 | # define OPENAT openat |
4973cbe5 UD |
31 | #endif |
32 | ||
d369ad76 UD |
33 | |
34 | #define OPENAT_NOT_CANCEL CONCAT (OPENAT) | |
35 | #define CONCAT(name) CONCAT2 (name) | |
36 | #define CONCAT2(name) __##name##_nocancel | |
37 | ||
38 | ||
4973cbe5 | 39 | int |
d369ad76 | 40 | OPENAT_NOT_CANCEL (fd, file, oflag, mode) |
4973cbe5 UD |
41 | int fd; |
42 | const char *file; | |
43 | int oflag; | |
d369ad76 | 44 | mode_t mode; |
4973cbe5 | 45 | { |
7c65e900 UD |
46 | |
47 | /* We have to add the O_LARGEFILE flag for openat64. */ | |
48 | #ifdef MORE_OFLAGS | |
49 | oflag |= MORE_OFLAGS; | |
50 | #endif | |
51 | ||
809fdf0d | 52 | return INLINE_SYSCALL (openat, 4, fd, file, oflag, mode); |
4973cbe5 | 53 | } |
d369ad76 | 54 | |
e2c7e1de RM |
55 | #define UNDERIZE(name) UNDERIZE_1 (name) |
56 | #define UNDERIZE_1(name) __##name | |
57 | #define __OPENAT UNDERIZE (OPENAT) | |
58 | ||
d369ad76 UD |
59 | |
60 | /* Open FILE with access OFLAG. Interpret relative paths relative to | |
61 | the directory associated with FD. If OFLAG includes O_CREAT, a | |
62 | third argument is the file protection. */ | |
63 | int | |
e2c7e1de | 64 | __OPENAT (fd, file, oflag) |
d369ad76 UD |
65 | int fd; |
66 | const char *file; | |
67 | int oflag; | |
68 | { | |
69 | mode_t mode = 0; | |
70 | if (oflag & O_CREAT) | |
71 | { | |
72 | va_list arg; | |
73 | va_start (arg, oflag); | |
74 | mode = va_arg (arg, mode_t); | |
75 | va_end (arg); | |
76 | } | |
77 | ||
78 | if (SINGLE_THREAD_P) | |
79 | return OPENAT_NOT_CANCEL (fd, file, oflag, mode); | |
80 | ||
81 | int oldtype = LIBC_CANCEL_ASYNC (); | |
82 | ||
83 | int res = OPENAT_NOT_CANCEL (fd, file, oflag, mode); | |
84 | ||
85 | LIBC_CANCEL_RESET (oldtype); | |
86 | ||
87 | return res; | |
88 | } | |
e2c7e1de RM |
89 | libc_hidden_def (__OPENAT) |
90 | weak_alias (__OPENAT, OPENAT) |