pread_write.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # ifdef __mips64
  25. _syscall4(ssize_t, pread, int, fd, void *, buf, size_t, count, off_t, offset);
  26. # else /* !__mips64 */
  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. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  37. {
  38. uint32_t low = offset & 0xffffffff;
  39. uint32_t high = offset >> 32;
  40. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  41. }
  42. weak_alias(__libc_pread64,pread64)
  43. # endif /* __UCLIBC_HAS_LFS__ */
  44. # endif /* !__mips64 */
  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. # ifdef __mips64
  55. _syscall4(ssize_t, pwrite, int, fd, const void *, buf, size_t, count, off_t, offset);
  56. # else /* !__mips64 */
  57. # define __NR___syscall_pwrite __NR_pwrite
  58. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  59. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  60. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  61. {
  62. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  63. }
  64. weak_alias(__libc_pwrite,pwrite)
  65. # ifdef __UCLIBC_HAS_LFS__
  66. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  67. {
  68. uint32_t low = offset & 0xffffffff;
  69. uint32_t high = offset >> 32;
  70. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  71. }
  72. weak_alias(__libc_pwrite64,pwrite64)
  73. # endif /* __UCLIBC_HAS_LFS__ */
  74. # endif /* !__mips64 */
  75. #endif /* __NR_pwrite */