]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/fcntl.c
1 /* Copyright (C) 2000, 2002 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 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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <sys/syscall.h>
26 #include "../kernel-features.h"
31 extern int __syscall_fcntl (int __fd
, int __cmd
, ...);
33 extern int __syscall_fcntl64 (int __fd
, int __cmd
, ...);
36 #if __ASSUME_FCNTL64 == 0
37 /* This variable is shared with all files that check for fcntl64. */
38 int __have_no_fcntl64
;
42 __libc_fcntl (int fd
, int cmd
, ...)
48 arg
= va_arg (ap
, void *);
51 #if __ASSUME_FCNTL64 > 0
52 return INLINE_SYSCALL (fcntl64
, 3, fd
, cmd
, arg
);
55 if (! __have_no_fcntl64
)
57 int result
= INLINE_SYSCALL (fcntl64
, 3, fd
, cmd
, arg
);
58 if (result
>= 0 || errno
!= ENOSYS
)
61 __have_no_fcntl64
= 1;
67 /* Convert arg from flock64 to flock and back. */
70 struct flock64
*fl64
= arg
;
73 fl
.l_start
= (off_t
)fl64
->l_start
;
74 /* Check if we can represent the values with the smaller type. */
75 if ((off64_t
) fl
.l_start
!= fl64
->l_start
)
77 __set_errno (EOVERFLOW
);
80 fl
.l_len
= (off_t
) fl64
->l_len
;
81 /* Check if we can represent the values with the smaller type. */
82 if ((off64_t
) fl
.l_len
!= fl64
->l_len
)
84 __set_errno (EOVERFLOW
);
87 fl
.l_type
= fl64
->l_type
;
88 fl
.l_whence
= fl64
->l_whence
;
89 fl
.l_pid
= fl64
->l_pid
;
91 res
= INLINE_SYSCALL (fcntl
, 3, fd
, F_GETLK
, &fl
);
94 /* Everything ok, convert back. */
95 fl64
->l_type
= fl
.l_type
;
96 fl64
->l_whence
= fl
.l_whence
;
97 fl64
->l_start
= fl
.l_start
;
98 fl64
->l_len
= fl
.l_len
;
99 fl64
->l_pid
= fl
.l_pid
;
105 /* Try to convert arg from flock64 to flock. */
108 struct flock64
*fl64
= arg
;
110 fl
.l_start
= (off_t
) fl64
->l_start
;
111 /* Check if we can represent the values with the smaller type. */
112 if ((off64_t
) fl
.l_start
!= fl64
->l_start
)
114 __set_errno (EOVERFLOW
);
117 fl
.l_len
= (off_t
)fl64
->l_len
;
118 /* Check if we can represent the values with the smaller type. */
119 if ((off64_t
) fl
.l_len
!= fl64
->l_len
)
121 __set_errno (EOVERFLOW
);
124 fl
.l_type
= fl64
->l_type
;
125 fl
.l_whence
= fl64
->l_whence
;
126 fl
.l_pid
= fl64
->l_pid
;
127 assert (F_SETLK
- F_SETLKW
== F_SETLK64
- F_SETLKW64
);
128 return INLINE_SYSCALL (fcntl
, 3, fd
, cmd
+ F_SETLK
- F_SETLK64
, &fl
);
131 return INLINE_SYSCALL (fcntl
, 3, fd
, cmd
, arg
);
134 #endif /* __ASSUME_FCNTL64 */
136 INTDEF2(__libc_fcntl
, __fcntl
);
138 weak_alias (__libc_fcntl
, __fcntl
)
139 weak_alias (__libc_fcntl
, fcntl
)