pread_write.c 3.4 KB

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