]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/fcntl.c
RISC-V: Build Infastructure
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / fcntl.c
CommitLineData
688903eb 1/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
ce42435c
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/>. */
ce42435c 17
ce42435c
UD
18#include <fcntl.h>
19#include <stdarg.h>
9b8f8593
AZ
20#include <errno.h>
21#include <sysdep-cancel.h>
102dde84 22#include <not-cancel.h>
ce42435c 23
9b8f8593
AZ
24#ifndef __NR_fcntl64
25# define __NR_fcntl64 __NR_fcntl
26#endif
81c84bd9 27
9b8f8593
AZ
28#ifndef FCNTL_ADJUST_CMD
29# define FCNTL_ADJUST_CMD(__cmd) __cmd
30#endif
81c84bd9
UD
31
32static int
9b8f8593 33fcntl_common (int fd, int cmd, void *arg)
81c84bd9 34{
9b8f8593
AZ
35 if (cmd == F_GETOWN)
36 {
37 INTERNAL_SYSCALL_DECL (err);
38 struct f_owner_ex fex;
39 int res = INTERNAL_SYSCALL_CALL (fcntl64, err, fd, F_GETOWN_EX, &fex);
40 if (!INTERNAL_SYSCALL_ERROR_P (res, err))
41 return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
42
43 return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (res,
2caca60d 44 err));
9b8f8593 45 }
ce42435c 46
9b8f8593
AZ
47 return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
48}
ce42435c 49
d199bfb2 50int
102dde84 51__libc_fcntl (int fd, int cmd, ...)
ce42435c 52{
76d0a2c4
AJ
53 va_list ap;
54 void *arg;
55
56 va_start (ap, cmd);
57 arg = va_arg (ap, void *);
58 va_end (ap);
59
102dde84
AZ
60 cmd = FCNTL_ADJUST_CMD (cmd);
61
62 if (cmd == F_SETLKW || cmd == F_SETLKW64)
63 return SYSCALL_CANCEL (fcntl64, fd, cmd, (void *) arg);
64
9b8f8593 65 return fcntl_common (fd, cmd, arg);
ce42435c 66}
102dde84 67libc_hidden_def (__libc_fcntl)
ce42435c 68
102dde84 69#if !IS_IN (rtld)
ce42435c 70int
102dde84 71__fcntl_nocancel (int fd, int cmd, ...)
ce42435c
UD
72{
73 va_list ap;
74 void *arg;
75
76 va_start (ap, cmd);
77 arg = va_arg (ap, void *);
78 va_end (ap);
79
9b8f8593 80 return fcntl_common (fd, cmd, arg);
ce42435c 81}
102dde84
AZ
82#else
83strong_alias (__libc_fcntl, __fcntl_nocancel)
84#endif
85libc_hidden_def (__fcntl_nocancel)
ce42435c
UD
86
87weak_alias (__libc_fcntl, __fcntl)
88libc_hidden_weak (__fcntl)
89weak_alias (__libc_fcntl, fcntl)