pread_write.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
  18. # ifdef __NR_pread
  19. # error "__NR_pread and __NR_pread64 both defined???"
  20. # endif
  21. # define __NR_pread __NR_pread64
  22. #endif
  23. #ifdef __NR_pread
  24. extern __typeof(pread) __libc_pread;
  25. # ifdef __mips64
  26. _syscall4(ssize_t, pread, int, fd, void *, buf, size_t, count, off_t, offset);
  27. # else /* !__mips64 */
  28. # define __NR___syscall_pread __NR_pread
  29. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  30. 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. uint32_t low = offset & 0xffffffff;
  41. uint32_t high = offset >> 32;
  42. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  43. }
  44. weak_alias(__libc_pread64,pread64)
  45. # endif /* __UCLIBC_HAS_LFS__ */
  46. # endif /* !__mips64 */
  47. #endif /* __NR_pread */
  48. /**********************************************************************/
  49. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  50. # ifdef __NR_pwrite
  51. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  52. # endif
  53. # define __NR_pwrite __NR_pwrite64
  54. #endif
  55. #ifdef __NR_pwrite
  56. extern __typeof(pwrite) __libc_pwrite;
  57. # ifdef __mips64
  58. _syscall4(ssize_t, pwrite, int, fd, const void *, buf, size_t, count, off_t, offset);
  59. # else /* !__mips64 */
  60. # define __NR___syscall_pwrite __NR_pwrite
  61. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  62. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  63. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  64. {
  65. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  66. }
  67. weak_alias(__libc_pwrite,pwrite)
  68. # ifdef __UCLIBC_HAS_LFS__
  69. extern __typeof(pwrite64) __libc_pwrite64;
  70. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  71. {
  72. uint32_t low = offset & 0xffffffff;
  73. uint32_t high = offset >> 32;
  74. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  75. }
  76. weak_alias(__libc_pwrite64,pwrite64)
  77. # endif /* __UCLIBC_HAS_LFS__ */
  78. # endif /* !__mips64 */
  79. #endif /* __NR_pwrite */