2000-08-12 08:22:14 +00:00
|
|
|
/* Copyright (C) 2000 Free Software Foundation, Inc.
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
2000-10-25 17:19:53 +00:00
|
|
|
#include <assert.h>
|
2000-08-12 08:22:14 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include "../kernel-features.h"
|
|
|
|
|
2000-09-07 15:46:19 +00:00
|
|
|
extern int __syscall_fcntl (int __fd, int __cmd, ...);
|
|
|
|
#ifdef __NR_fcntl64
|
|
|
|
extern int __syscall_fcntl64 (int __fd, int __cmd, ...);
|
|
|
|
#endif
|
2000-08-12 08:22:14 +00:00
|
|
|
|
2000-08-12 08:46:30 +00:00
|
|
|
#if __ASSUME_FCNTL64 == 0
|
2000-08-12 08:39:46 +00:00
|
|
|
/* This variable is shared with all files that check for fcntl64. */
|
2000-08-12 10:01:20 +00:00
|
|
|
int __have_no_fcntl64;
|
2000-08-12 08:39:46 +00:00
|
|
|
#endif
|
|
|
|
|
2000-08-12 08:22:14 +00:00
|
|
|
int
|
|
|
|
__libc_fcntl (int fd, int cmd, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
void *arg;
|
|
|
|
|
|
|
|
va_start (ap, cmd);
|
|
|
|
arg = va_arg (ap, void *);
|
|
|
|
va_end (ap);
|
|
|
|
|
2000-08-12 08:39:46 +00:00
|
|
|
#if __ASSUME_FCNTL64 > 0
|
|
|
|
return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
|
|
|
|
#else
|
|
|
|
# ifdef __NR_fcntl64
|
|
|
|
if (! __have_no_fcntl64)
|
|
|
|
{
|
|
|
|
int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
|
|
|
|
if (result >= 0 || errno != ENOSYS)
|
|
|
|
return result;
|
2000-08-12 08:22:14 +00:00
|
|
|
|
2000-08-12 08:39:46 +00:00
|
|
|
__have_no_fcntl64 = 1;
|
|
|
|
}
|
2000-08-12 08:22:14 +00:00
|
|
|
# endif
|
2000-08-12 08:39:46 +00:00
|
|
|
switch (cmd)
|
2000-08-12 08:22:14 +00:00
|
|
|
{
|
2000-08-12 08:39:46 +00:00
|
|
|
case F_GETLK64:
|
|
|
|
/* Convert arg from flock64 to flock and back. */
|
|
|
|
{
|
|
|
|
struct flock fl;
|
|
|
|
struct flock64 *fl64 = arg;
|
|
|
|
int res;
|
2000-08-12 08:22:14 +00:00
|
|
|
|
2000-08-12 08:39:46 +00:00
|
|
|
fl.l_start = (off_t)fl64->l_start;
|
|
|
|
/* Check if we can represent the values with the smaller type. */
|
2000-08-12 08:46:30 +00:00
|
|
|
if ((off64_t) fl.l_start != fl64->l_start)
|
2000-08-12 08:39:46 +00:00
|
|
|
{
|
|
|
|
__set_errno (EOVERFLOW);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-08-12 08:46:30 +00:00
|
|
|
fl.l_len = (off_t) fl64->l_len;
|
2000-08-12 08:39:46 +00:00
|
|
|
/* Check if we can represent the values with the smaller type. */
|
2000-08-12 08:46:30 +00:00
|
|
|
if ((off64_t) fl.l_len != fl64->l_len)
|
2000-08-12 08:39:46 +00:00
|
|
|
{
|
|
|
|
__set_errno (EOVERFLOW);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fl.l_type = fl64->l_type;
|
|
|
|
fl.l_whence = fl64->l_whence;
|
|
|
|
fl.l_pid = fl64->l_pid;
|
|
|
|
|
2000-10-25 17:19:53 +00:00
|
|
|
res = INLINE_SYSCALL (fcntl, 3, fd, F_GETLK, &fl);
|
2000-08-12 08:39:46 +00:00
|
|
|
if (res != 0)
|
|
|
|
return res;
|
|
|
|
/* Everything ok, convert back. */
|
|
|
|
fl64->l_type = fl.l_type;
|
|
|
|
fl64->l_whence = fl.l_whence;
|
|
|
|
fl64->l_start = fl.l_start;
|
|
|
|
fl64->l_len = fl.l_len;
|
|
|
|
fl64->l_pid = fl.l_pid;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case F_SETLK64:
|
|
|
|
case F_SETLKW64:
|
|
|
|
/* Try to convert arg from flock64 to flock. */
|
|
|
|
{
|
|
|
|
struct flock fl;
|
|
|
|
struct flock64 *fl64 = arg;
|
2000-08-12 08:46:30 +00:00
|
|
|
|
|
|
|
fl.l_start = (off_t) fl64->l_start;
|
2000-08-12 08:39:46 +00:00
|
|
|
/* Check if we can represent the values with the smaller type. */
|
2000-08-12 08:46:30 +00:00
|
|
|
if ((off64_t) fl.l_start != fl64->l_start)
|
2000-08-12 08:39:46 +00:00
|
|
|
{
|
|
|
|
__set_errno (EOVERFLOW);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fl.l_len = (off_t)fl64->l_len;
|
|
|
|
/* Check if we can represent the values with the smaller type. */
|
2000-08-12 08:46:30 +00:00
|
|
|
if ((off64_t) fl.l_len != fl64->l_len)
|
2000-08-12 08:39:46 +00:00
|
|
|
{
|
|
|
|
__set_errno (EOVERFLOW);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fl.l_type = fl64->l_type;
|
|
|
|
fl.l_whence = fl64->l_whence;
|
|
|
|
fl.l_pid = fl64->l_pid;
|
2000-10-25 17:19:53 +00:00
|
|
|
assert (F_SETLK - F_SETLKW == F_SETLK64 - F_SETLKW64);
|
|
|
|
return INLINE_SYSCALL (fcntl, 3, fd, cmd + F_SETLK - F_SETLK64, &fl);
|
2000-08-12 08:39:46 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
#endif /* __ASSUME_FCNTL64 */
|
2000-08-12 08:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
weak_alias (__libc_fcntl, __fcntl)
|
|
|
|
weak_alias (__libc_fcntl, fcntl)
|