This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Consolidate lseek/lseek64/llseek implementations


On Aug 25 2016, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> diff --git a/sysdeps/unix/sysv/linux/lseek.c b/sysdeps/unix/sysv/linux/lseek.c
> new file mode 100644
> index 0000000..15bee74
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/lseek.c
> @@ -0,0 +1,54 @@
> +/* Copyright (C) 2016 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 Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 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
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library.  If not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sysdep.h>
> +#include <errno.h>
> +
> +#ifndef __OFF_T_MATCHES_OFF64_T
> +
> +/* Test for overflows of structures where we ask the kernel to fill them
> +   in with standard 64-bit syscalls but return them through APIs that
> +   only expose the low 32 bits of some fields.  */
> +
> +static inline off_t lseek_overflow (loff_t res)
> +{
> +  off_t retval = (off_t) res;
> +  if (retval == res)
> +    return retval;
> +
> +  __set_errno (EOVERFLOW);
> +  return (off_t) -1;
> +}
> +
> +off_t
> +__lseek (int fd, off_t offset, int whence)
> +{
> +# ifdef __NR__llseek
> +  loff_t res;
> +  int rc = INLINE_SYSCALL_CALL (_llseek, fd, (off_t)(offset >> 31),
> +				(off_t) offset, &res, whence);

The casts are no-ops.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]