]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/fcntl_nocancel.c
dd336b56796d8c5a1020aa83b9b458a4d540fbda
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / fcntl_nocancel.c
1 /* Linux fcntl syscall implementation -- non-cancellable.
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <fcntl.h>
20 #include <stdarg.h>
21 #include <errno.h>
22 #include <sysdep-cancel.h>
23 #include <not-cancel.h>
24
25 #ifndef __NR_fcntl64
26 # define __NR_fcntl64 __NR_fcntl
27 #endif
28
29 #ifndef FCNTL_ADJUST_CMD
30 # define FCNTL_ADJUST_CMD(__cmd) __cmd
31 #endif
32
33 int
34 __fcntl64_nocancel (int fd, int cmd, ...)
35 {
36 va_list ap;
37 void *arg;
38
39 va_start (ap, cmd);
40 arg = va_arg (ap, void *);
41 va_end (ap);
42
43 cmd = FCNTL_ADJUST_CMD (cmd);
44
45 return __fcntl64_nocancel_adjusted (fd, cmd, arg);
46 }
47 hidden_def (__fcntl64_nocancel)
48
49 int
50 __fcntl64_nocancel_adjusted (int fd, int cmd, void *arg)
51 {
52 if (cmd == F_GETOWN)
53 {
54 INTERNAL_SYSCALL_DECL (err);
55 struct f_owner_ex fex;
56 int res = INTERNAL_SYSCALL_CALL (fcntl64, err, fd, F_GETOWN_EX, &fex);
57 if (!INTERNAL_SYSCALL_ERROR_P (res, err))
58 return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
59
60 return INLINE_SYSCALL_ERROR_RETURN_VALUE
61 (INTERNAL_SYSCALL_ERRNO (res, err));
62 }
63
64 return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
65 }