]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/fcntl.c
1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #include <sys/syscall.h>
25 #include "../kernel-features.h"
28 #if __ASSUME_FCNTL64 == 0
29 /* This variable is shared with all files that check for fcntl64. */
30 static int __have_no_fcntl64
;
34 __libc_fcntl (int fd
, int cmd
, ...)
40 arg
= va_arg (ap
, void *);
43 #if __ASSUME_FCNTL64 > 0
44 return INLINE_SYSCALL (fcntl64
, 3, fd
, cmd
, arg
);
47 if (! __have_no_fcntl64
)
49 int result
= INLINE_SYSCALL (fcntl64
, 3, fd
, cmd
, arg
);
50 if (result
>= 0 || errno
!= ENOSYS
)
53 __have_no_fcntl64
= 1;
59 /* Convert arg from flock64 to flock and back. */
62 struct flock64
*fl64
= arg
;
65 fl
.l_start
= (off_t
)fl64
->l_start
;
66 /* Check if we can represent the values with the smaller type. */
67 if ((off64_t
) fl
.l_start
!= fl64
->l_start
)
69 __set_errno (EOVERFLOW
);
72 fl
.l_len
= (off_t
) fl64
->l_len
;
73 /* Check if we can represent the values with the smaller type. */
74 if ((off64_t
) fl
.l_len
!= fl64
->l_len
)
76 __set_errno (EOVERFLOW
);
79 fl
.l_type
= fl64
->l_type
;
80 fl
.l_whence
= fl64
->l_whence
;
81 fl
.l_pid
= fl64
->l_pid
;
83 res
= INLINE_SYSCALL (fcntl
, 3, fd
, cmd
, &fl
);
86 /* Everything ok, convert back. */
87 fl64
->l_type
= fl
.l_type
;
88 fl64
->l_whence
= fl
.l_whence
;
89 fl64
->l_start
= fl
.l_start
;
90 fl64
->l_len
= fl
.l_len
;
91 fl64
->l_pid
= fl
.l_pid
;
97 /* Try to convert arg from flock64 to flock. */
100 struct flock64
*fl64
= arg
;
102 fl
.l_start
= (off_t
) fl64
->l_start
;
103 /* Check if we can represent the values with the smaller type. */
104 if ((off64_t
) fl
.l_start
!= fl64
->l_start
)
106 __set_errno (EOVERFLOW
);
109 fl
.l_len
= (off_t
)fl64
->l_len
;
110 /* Check if we can represent the values with the smaller type. */
111 if ((off64_t
) fl
.l_len
!= fl64
->l_len
)
113 __set_errno (EOVERFLOW
);
116 fl
.l_type
= fl64
->l_type
;
117 fl
.l_whence
= fl64
->l_whence
;
118 fl
.l_pid
= fl64
->l_pid
;
119 return INLINE_SYSCALL (fcntl
, 3, fd
, cmd
, &fl
);
122 return INLINE_SYSCALL (fcntl
, 3, fd
, cmd
, arg
);
125 #endif /* __ASSUME_FCNTL64 */
128 weak_alias (__libc_fcntl
, __fcntl
)
129 weak_alias (__libc_fcntl
, fcntl
)