pread_write.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #include <sgidefs.h>
  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. extern __typeof(pread) __libc_pread;
  27. extern __typeof(pwrite) __libc_pwrite;
  28. #ifdef __UCLIBC_HAS_LFS__
  29. extern __typeof(pread64) __libc_pread64;
  30. extern __typeof(pwrite64) __libc_pwrite64;
  31. #endif
  32. #include <bits/kernel_types.h>
  33. #ifdef __NR_pread
  34. # if _MIPS_SIM == _MIPS_SIM_ABI64
  35. # define __NR___libc_pread __NR_pread
  36. _syscall4(ssize_t, __libc_pread, int, fd, void *, buf, size_t, count, off_t, offset);
  37. weak_alias (__libc_pread, pread)
  38. # ifdef __UCLIBC_HAS_LFS__
  39. # define __NR___libc_pread64 __NR_pread
  40. _syscall4(ssize_t, __libc_pread64, int, fd, void *, buf, size_t, count, off64_t, offset);
  41. weak_alias (__libc_pread64, pread64)
  42. # endif /* __UCLIBC_HAS_LFS__ */
  43. # else /* O32 || N32 */
  44. # define __NR___syscall_pread __NR_pread
  45. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  46. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  47. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  48. {
  49. return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  50. }
  51. weak_alias(__libc_pread,pread)
  52. # ifdef __UCLIBC_HAS_LFS__
  53. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  54. {
  55. uint32_t low = offset & 0xffffffff;
  56. uint32_t high = offset >> 32;
  57. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  58. }
  59. weak_alias(__libc_pread64,pread64)
  60. # endif /* __UCLIBC_HAS_LFS__ */
  61. # endif /* O32 || N32 */
  62. #endif /* __NR_pread */
  63. /**********************************************************************/
  64. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  65. # ifdef __NR_pwrite
  66. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  67. # endif
  68. # define __NR_pwrite __NR_pwrite64
  69. #endif
  70. #ifdef __NR_pwrite
  71. # if _MIPS_SIM == _MIPS_SIM_ABI64
  72. # define __NR___libc_pwrite __NR_pwrite
  73. _syscall4(ssize_t, __libc_pwrite, int, fd, const void *, buf, size_t, count, off_t, offset);
  74. weak_alias (__libc_pwrite, pwrite)
  75. # ifdef __UCLIBC_HAS_LFS__
  76. # define __NR___libc_pwrite64 __NR_pwrite
  77. _syscall4(ssize_t, __libc_pwrite64, int, fd, const void *, buf, size_t, count, off64_t, offset);
  78. weak_alias (__libc_pwrite64, pwrite64)
  79. # endif /* __UCLIBC_HAS_LFS__ */
  80. # else /* O32 || N32 */
  81. # define __NR___syscall_pwrite __NR_pwrite
  82. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  83. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  84. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  85. {
  86. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  87. }
  88. weak_alias(__libc_pwrite,pwrite)
  89. # ifdef __UCLIBC_HAS_LFS__
  90. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  91. {
  92. uint32_t low = offset & 0xffffffff;
  93. uint32_t high = offset >> 32;
  94. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  95. }
  96. weak_alias(__libc_pwrite64,pwrite64)
  97. # endif /* __UCLIBC_HAS_LFS__ */
  98. # endif /* O32 || N32 */
  99. #endif /* __NR_pwrite */