Remove stray includes of kernel-features.h.
[glibc.git] / sysdeps / unix / sysv / linux / generic / wordsize-32 / fcntl.c
blob17ddcf68a8e76f10939527e683e52d5df8147a30
1 /* Copyright (C) 2011-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
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.
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.
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/>. */
19 #include <assert.h>
20 #include <errno.h>
21 #include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
22 #include <fcntl.h>
23 #include <stdarg.h>
25 #include <sys/syscall.h>
28 static int
29 do_fcntl (int fd, int cmd, void *arg)
31 if (cmd != F_GETOWN)
32 return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
34 INTERNAL_SYSCALL_DECL (err);
35 struct f_owner_ex fex;
36 int res = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETOWN_EX, &fex);
37 if (!INTERNAL_SYSCALL_ERROR_P (res, err))
38 return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
40 __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
41 return -1;
45 #ifndef NO_CANCELLATION
46 int
47 __fcntl_nocancel (int fd, int cmd, ...)
49 va_list ap;
50 void *arg;
52 va_start (ap, cmd);
53 arg = va_arg (ap, void *);
54 va_end (ap);
56 return do_fcntl (fd, cmd, arg);
58 #endif
61 int
62 __libc_fcntl (int fd, int cmd, ...)
64 va_list ap;
65 void *arg;
67 va_start (ap, cmd);
68 arg = va_arg (ap, void *);
69 va_end (ap);
71 if (SINGLE_THREAD_P || cmd != F_SETLKW)
72 return do_fcntl (fd, cmd, arg);
74 int oldtype = LIBC_CANCEL_ASYNC ();
76 int result = do_fcntl (fd, cmd, arg);
78 LIBC_CANCEL_RESET (oldtype);
80 return result;
82 libc_hidden_def (__libc_fcntl)
84 weak_alias (__libc_fcntl, __fcntl)
85 libc_hidden_weak (__fcntl)
86 weak_alias (__libc_fcntl, fcntl)