Consolidate non cancellable close call
[glibc.git] / sysdeps / unix / sysv / linux / not-cancel.h
blob51824515da98cd61f48694454add1acdbdfca5ab
1 /* Uncancelable versions of cancelable interfaces. Linux/NPTL version.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef NOT_CANCEL_H
21 # define NOT_CANCEL_H
23 #include <fcntl.h>
24 #include <sysdep.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include <sys/syscall.h>
29 /* Non cancellable open syscall. */
30 __typeof (open) __open_nocancel;
31 libc_hidden_proto (__open_nocancel)
33 /* Non cancellable open syscall (LFS version). */
34 __typeof (open64) __open64_nocancel;
35 libc_hidden_proto (__open64_nocancel)
37 /* Non cancellable openat syscall. */
38 __typeof (openat) __openat_nocancel;
39 libc_hidden_proto (__openat_nocancel)
41 /* Non cacellable openat syscall (LFS version). */
42 __typeof (openat64) __openat64_nocancel;
43 libc_hidden_proto (__openat64_nocancel)
45 /* Non cancellable read syscall. */
46 __typeof (__read) __read_nocancel;
47 libc_hidden_proto (__read_nocancel)
49 /* Uncancelable write. */
50 __typeof (__write) __write_nocancel;
51 libc_hidden_proto (__write_nocancel)
53 /* Uncancelable close. */
54 __typeof (__close) __close_nocancel;
55 libc_hidden_proto (__close_nocancel)
57 /* Non cancellable close syscall that does not also set errno in case of
58 failure. */
59 static inline void
60 __close_nocancel_nostatus (int fd)
62 __close_nocancel (fd);
65 /* Uncancelable writev. */
66 #define writev_not_cancel_no_status(fd, iov, n) \
67 (void) ({ INTERNAL_SYSCALL_DECL (err); \
68 INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
70 /* Uncancelable fcntl. */
71 #define fcntl_not_cancel(fd, cmd, val) \
72 __fcntl_nocancel (fd, cmd, val)
74 /* Uncancelable waitpid. */
75 #define __waitpid_nocancel(pid, stat_loc, options) \
76 INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
77 #define waitpid_not_cancel(pid, stat_loc, options) \
78 __waitpid_nocancel(pid, stat_loc, options)
80 /* Uncancelable pause. */
81 #define pause_not_cancel() \
82 ({ sigset_t set; \
83 int __rc = INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, \
84 _NSIG / 8); \
85 if (__rc == 0) \
86 __rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8); \
87 __rc; \
90 /* Uncancelable nanosleep. */
91 #define nanosleep_not_cancel(requested_time, remaining) \
92 INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
94 /* Uncancelable sigsuspend. */
95 #define sigsuspend_not_cancel(set) \
96 INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8)
98 #endif /* NOT_CANCEL_H */