diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/sysdeps/linux/common/pread_write.c | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/libc/sysdeps/linux/common/pread_write.c b/libc/sysdeps/linux/common/pread_write.c index 48fe7dd4b..3d04bb7e5 100644 --- a/libc/sysdeps/linux/common/pread_write.c +++ b/libc/sysdeps/linux/common/pread_write.c @@ -15,71 +15,73 @@ #include <sys/syscall.h> #include <unistd.h> -#include <stdint.h> #include <endian.h> +#include <bits/wordsize.h> +#include <cancel.h> -extern __typeof(pread) __libc_pread; -extern __typeof(pwrite) __libc_pwrite; -#ifdef __UCLIBC_HAS_LFS__ -extern __typeof(pread64) __libc_pread64; -extern __typeof(pwrite64) __libc_pwrite64; -#endif - -#ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */ +#ifdef __NR_pread64 # undef __NR_pread # define __NR_pread __NR_pread64 #endif +#ifdef __NR_pwrite64 +# undef __NR_pwrite +# define __NR_pwrite __NR_pwrite64 +#endif -#include <bits/kernel_types.h> - -#ifdef __NR_pread +#ifndef MY_PREAD +# ifdef __NR_pread +# define __NR___syscall_pread __NR_pread +static _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, + size_t, count, off_t, offset_hi, off_t, offset_lo) +# define MY_PREAD(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF_HI_LO(offset)) +# define MY_PREAD64(fd, buf, count, offset) __syscall_pread(fd, buf, count, OFF64_HI_LO(offset)) +#endif -# define __NR___syscall_pread __NR_pread -static __inline__ _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, - size_t, count, off_t, offset_hi, off_t, offset_lo) +#ifndef MY_PWRITE +# ifdef __NR_pwrite +# define __NR___syscall_pwrite __NR_pwrite +static _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf, + size_t, count, off_t, offset_hi, off_t, offset_lo) +# define MY_PWRITE(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF_HI_LO(offset)) +# define MY_PWRITE64(fd, buf, count, offset) __syscall_pwrite(fd, buf, count, OFF64_HI_LO(offset)) +#endif -ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset) +static ssize_t __NC(pread)(int fd, void *buf, size_t count, off_t offset) { - return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset)); + return MY_PREAD(fd, buf, count, offset); } -weak_alias(__libc_pread,pread) +CANCELLABLE_SYSCALL(ssize_t, pread, (int fd, void *buf, size_t count, off_t offset), + (fd, buf, count, offset)) -# ifdef __UCLIBC_HAS_LFS__ -ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset) +static ssize_t __NC(pwrite)(int fd, const void *buf, size_t count, off_t offset) { - uint32_t low = offset & 0xffffffff; - uint32_t high = offset >> 32; - return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(high, low)); + return MY_PWRITE(fd, buf, count, offset); } -weak_alias(__libc_pread64,pread64) -# endif /* __UCLIBC_HAS_LFS__ */ +CANCELLABLE_SYSCALL(ssize_t, pwrite, (int fd, const void *buf, size_t count, off_t offset), + (fd, buf, count, offset)) -#endif /* __NR_pread */ - -#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */ -# undef __NR_pwrite -# define __NR_pwrite __NR_pwrite64 -#endif - -#ifdef __NR_pwrite - -# define __NR___syscall_pwrite __NR_pwrite -static __inline__ _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf, - size_t, count, off_t, offset_hi, off_t, offset_lo) - -ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset) +#ifdef __UCLIBC_HAS_LFS__ +# if __WORDSIZE == 32 +static ssize_t __NC(pread64)(int fd, void *buf, size_t count, off64_t offset) { - return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset)); + return MY_PREAD64(fd, buf, count, offset); } -weak_alias(__libc_pwrite,pwrite) +CANCELLABLE_SYSCALL(ssize_t, pread64, (int fd, void *buf, size_t count, off64_t offset), + (fd, buf, count, offset)) -# ifdef __UCLIBC_HAS_LFS__ -ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset) +static ssize_t __NC(pwrite64)(int fd, const void *buf, size_t count, off64_t offset) { - uint32_t low = offset & 0xffffffff; - uint32_t high = offset >> 32; - return __syscall_pwrite(fd, buf, count, __LONG_LONG_PAIR(high, low)); + return MY_PWRITE64(fd, buf, count, offset); } -weak_alias(__libc_pwrite64,pwrite64) -# endif /* __UCLIBC_HAS_LFS__ */ -#endif /* __NR_pwrite */ +CANCELLABLE_SYSCALL(ssize_t, pwrite64, (int fd, const void *buf, size_t count, off64_t offset), + (fd, buf, count, offset)) +# else +# ifdef __LINUXTHREADS_OLD__ +weak_alias(pread,pread64) +weak_alias(pwrite,pwrite64) +# else +strong_alias_untyped(pread,pread64) +strong_alias_untyped(pwrite,pwrite64) +# endif +# endif +#endif |