]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
Add sysdeps/unix/sysv/linux/generic/.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / generic / wordsize-32 / fcntl.c
1 /* Copyright (C) 2011 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #include <assert.h>
21 #include <errno.h>
22 #include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
23 #include <fcntl.h>
24 #include <stdarg.h>
25
26 #include <sys/syscall.h>
27 #include <kernel-features.h>
28
29
30 static int
31 do_fcntl (int fd, int cmd, void *arg)
32 {
33 if (cmd != F_GETOWN)
34 return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
35
36 INTERNAL_SYSCALL_DECL (err);
37 struct f_owner_ex fex;
38 int res = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETOWN_EX, &fex);
39 if (!INTERNAL_SYSCALL_ERROR_P (res, err))
40 return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
41
42 __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
43 return -1;
44 }
45
46
47 #ifndef NO_CANCELLATION
48 int
49 __fcntl_nocancel (int fd, int cmd, ...)
50 {
51 va_list ap;
52 void *arg;
53
54 va_start (ap, cmd);
55 arg = va_arg (ap, void *);
56 va_end (ap);
57
58 return do_fcntl (fd, cmd, arg);
59 }
60 #endif
61
62
63 int
64 __libc_fcntl (int fd, int cmd, ...)
65 {
66 va_list ap;
67 void *arg;
68
69 va_start (ap, cmd);
70 arg = va_arg (ap, void *);
71 va_end (ap);
72
73 if (SINGLE_THREAD_P || cmd != F_SETLKW)
74 return do_fcntl (fd, cmd, arg);
75
76 int oldtype = LIBC_CANCEL_ASYNC ();
77
78 int result = do_fcntl (fd, cmd, arg);
79
80 LIBC_CANCEL_RESET (oldtype);
81
82 return result;
83 }
84 libc_hidden_def (__libc_fcntl)
85
86 weak_alias (__libc_fcntl, __fcntl)
87 libc_hidden_weak (__fcntl)
88 weak_alias (__libc_fcntl, fcntl)