pread_write.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /*
  8. * Based in part on the files
  9. * ./sysdeps/unix/sysv/linux/pwrite.c,
  10. * ./sysdeps/unix/sysv/linux/pread.c,
  11. * sysdeps/posix/pread.c
  12. * sysdeps/posix/pwrite.c
  13. * from GNU libc 2.2.5, but reworked considerably...
  14. */
  15. #include <sys/syscall.h>
  16. #include <unistd.h>
  17. #include <stdint.h>
  18. #include <endian.h>
  19. #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
  20. # ifdef __NR_pread
  21. # error "__NR_pread and __NR_pread64 both defined???"
  22. # endif
  23. # define __NR_pread __NR_pread64
  24. #endif
  25. #ifdef __NR_pread
  26. extern __typeof(pread) __libc_pread;
  27. # define __NR___syscall_pread __NR_pread
  28. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  29. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  30. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  31. {
  32. return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR(offset >> 31,offset)));
  33. }
  34. weak_alias(__libc_pread,pread)
  35. # ifdef __UCLIBC_HAS_LFS__
  36. extern __typeof(pread64) __libc_pread64;
  37. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  38. {
  39. uint32_t low = offset & 0xffffffff;
  40. uint32_t high = offset >> 32;
  41. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  42. }
  43. weak_alias(__libc_pread64,pread64)
  44. # endif /* __UCLIBC_HAS_LFS__ */
  45. #endif /* __NR_pread */
  46. /**********************************************************************/
  47. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  48. # ifdef __NR_pwrite
  49. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  50. # endif
  51. # define __NR_pwrite __NR_pwrite64
  52. #endif
  53. #ifdef __NR_pwrite
  54. extern __typeof(pwrite) __libc_pwrite;
  55. # define __NR___syscall_pwrite __NR_pwrite
  56. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  57. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  58. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  59. {
  60. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset >> 31,offset)));
  61. }
  62. weak_alias(__libc_pwrite,pwrite)
  63. # ifdef __UCLIBC_HAS_LFS__
  64. extern __typeof(pwrite64) __libc_pwrite64;
  65. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  66. {
  67. uint32_t low = offset & 0xffffffff;
  68. uint32_t high = offset >> 32;
  69. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  70. }
  71. weak_alias(__libc_pwrite64,pwrite64)
  72. # endif /* __UCLIBC_HAS_LFS__ */
  73. #endif /* __NR_pwrite */