pread_write.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* vi: set sw=4 ts=4:
  2. *
  3. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. /* Based in part on the files
  8. * ./sysdeps/unix/sysv/linux/pwrite.c,
  9. * ./sysdeps/unix/sysv/linux/pread.c,
  10. * sysdeps/posix/pread.c
  11. * sysdeps/posix/pwrite.c
  12. * from GNU libc 2.2.5, but reworked considerably...
  13. */
  14. #include <sys/syscall.h>
  15. #include <unistd.h>
  16. #include <endian.h>
  17. #ifndef __UCLIBC_HAS_LFS__
  18. # define off64_t off_t
  19. #endif
  20. #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
  21. # ifdef __NR_pread
  22. # error "__NR_pread and __NR_pread64 both defined???"
  23. # endif
  24. # define __NR_pread __NR_pread64
  25. #endif
  26. #ifdef __NR_pread
  27. extern __typeof(pread) __libc_pread;
  28. # define __NR___syscall_pread __NR_pread
  29. static __inline__ _syscall6(ssize_t, __syscall_pread, int, fd,
  30. void *, buf, size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
  31. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  32. {
  33. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR(offset >> 31, offset)));
  34. }
  35. weak_alias(__libc_pread,pread)
  36. # ifdef __UCLIBC_HAS_LFS__
  37. extern __typeof(pread64) __libc_pread64;
  38. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  39. {
  40. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR(offset >> 32, offset)));
  41. }
  42. weak_alias(__libc_pread64,pread64)
  43. # endif /* __UCLIBC_HAS_LFS__ */
  44. #endif /* __NR_pread */
  45. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  46. # ifdef __NR_pwrite
  47. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  48. # endif
  49. # define __NR_pwrite __NR_pwrite64
  50. #endif
  51. #ifdef __NR_pwrite
  52. extern __typeof(pwrite) __libc_pwrite;
  53. # define __NR___syscall_pwrite __NR_pwrite
  54. static __inline__ _syscall6(ssize_t, __syscall_pwrite, int, fd,
  55. const void *, buf, size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo)
  56. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  57. {
  58. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR(offset >> 31, offset)));
  59. }
  60. weak_alias(__libc_pwrite,pwrite)
  61. # ifdef __UCLIBC_HAS_LFS__
  62. extern __typeof(pwrite64) __libc_pwrite64;
  63. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  64. {
  65. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR(offset >> 32, offset)));
  66. }
  67. weak_alias(__libc_pwrite64,pwrite64)
  68. # endif /* __UCLIBC_HAS_LFS__ */
  69. #endif /* __NR_pwrite */