1 /* Linux fcntl syscall implementation -- non-cancellable.
2 Copyright (C) 2018-2022 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 <https://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
__fcntl64_nocancel(int fd,int cmd,...)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 }
hidden_def(__fcntl64_nocancel)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 struct f_owner_ex fex;
55 int res = INTERNAL_SYSCALL_CALL (fcntl64, fd, F_GETOWN_EX, &fex);
56 if (!INTERNAL_SYSCALL_ERROR_P (res))
57 return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
58
59 return INLINE_SYSCALL_ERROR_RETURN_VALUE
60 (INTERNAL_SYSCALL_ERRNO (res));
61 }
62
63 return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
64 }
65