1 |
|
|
/* $OpenBSD: w_fcntl.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */ |
2 |
|
|
/* |
3 |
|
|
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> |
4 |
|
|
* |
5 |
|
|
* Permission to use, copy, modify, and distribute this software for any |
6 |
|
|
* purpose with or without fee is hereby granted, provided that the above |
7 |
|
|
* copyright notice and this permission notice appear in all copies. |
8 |
|
|
* |
9 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10 |
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11 |
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12 |
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 |
|
|
*/ |
17 |
|
|
|
18 |
|
|
#include <fcntl.h> |
19 |
|
|
#include <stdarg.h> |
20 |
|
|
#include "cancel.h" |
21 |
|
|
|
22 |
|
|
int |
23 |
|
|
fcntl(int fd, int cmd, ...) |
24 |
|
|
{ |
25 |
|
17732194 |
va_list ap; |
26 |
|
|
int ret; |
27 |
|
|
|
28 |
|
8866097 |
va_start(ap, cmd); |
29 |
✗✗✗✗ ✓✗✗✗ ✓✗✗✗ ✗ |
8866097 |
switch (cmd) { |
30 |
|
|
case F_DUPFD: |
31 |
|
|
case F_DUPFD_CLOEXEC: |
32 |
|
|
case F_SETFD: |
33 |
|
|
case F_SETFL: |
34 |
|
|
case F_SETOWN: |
35 |
✓✗ |
15107958 |
ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, int)); |
36 |
|
5035986 |
break; |
37 |
|
|
case F_GETFD: |
38 |
|
|
case F_GETFL: |
39 |
|
|
case F_GETOWN: |
40 |
|
|
case F_ISATTY: |
41 |
|
3830111 |
ret = HIDDEN(fcntl)(fd, cmd); |
42 |
|
3830111 |
break; |
43 |
|
|
case F_GETLK: |
44 |
|
|
case F_SETLK: |
45 |
|
|
ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, struct flock *)); |
46 |
|
|
break; |
47 |
|
|
case F_SETLKW: |
48 |
|
|
ENTER_CANCEL_POINT(1); |
49 |
|
|
ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, struct flock *)); |
50 |
|
|
LEAVE_CANCEL_POINT(ret == -1); |
51 |
|
|
break; |
52 |
|
|
default: /* should never happen? */ |
53 |
|
|
ret = HIDDEN(fcntl)(fd, cmd, va_arg(ap, void *)); |
54 |
|
|
break; |
55 |
|
|
} |
56 |
|
8866097 |
va_end(ap); |
57 |
|
8866097 |
return (ret); |
58 |
|
8866097 |
} |
59 |
|
|
DEF_CANCEL(fcntl); |