pread_write.c 3.5 KB

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