pread_write.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #define _GNU_SOURCE
  15. #define _LARGEFILE64_SOURCE
  16. #include <features.h>
  17. #undef __OPTIMIZE__
  18. /* We absolutely do _NOT_ want interfaces silently
  19. * * * renamed under us or very bad things will happen... */
  20. #ifdef __USE_FILE_OFFSET64
  21. # undef __USE_FILE_OFFSET64
  22. #endif
  23. #include <errno.h>
  24. #include <sys/types.h>
  25. #include <sys/syscall.h>
  26. #include <unistd.h>
  27. #include <stdint.h>
  28. #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
  29. # ifdef __NR_pread
  30. # error "__NR_pread and __NR_pread64 both defined???"
  31. # endif
  32. # define __NR_pread __NR_pread64
  33. #endif
  34. #ifdef __NR_pread
  35. #ifdef __mips64
  36. _syscall4(ssize_t, pread, int, fd, void *, buf, size_t, count, off_t, offset);
  37. #else /* !__mips64 */
  38. #define __NR___syscall_pread __NR_pread
  39. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  40. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  41. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  42. {
  43. return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  44. }
  45. strong_alias(__libc_pread,pread)
  46. #if defined __UCLIBC_HAS_LFS__
  47. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  48. {
  49. uint32_t low = offset & 0xffffffff;
  50. uint32_t high = offset >> 32;
  51. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  52. }
  53. strong_alias(__libc_pread64,pread64)
  54. #endif /* __UCLIBC_HAS_LFS__ */
  55. #endif /* !__mips64 */
  56. #endif /* __NR_pread */
  57. /**********************************************************************/
  58. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  59. # ifdef __NR_pwrite
  60. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  61. # endif
  62. # define __NR_pwrite __NR_pwrite64
  63. #endif
  64. #ifdef __NR_pwrite
  65. #ifdef __mips64
  66. _syscall4(ssize_t, pwrite, int, fd, const void *, buf, size_t, count, off_t, offset);
  67. #else /* !__mips64 */
  68. #define __NR___syscall_pwrite __NR_pwrite
  69. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  70. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  71. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  72. {
  73. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR(offset>>31,offset)));
  74. }
  75. strong_alias(__libc_pwrite,pwrite)
  76. #if defined __UCLIBC_HAS_LFS__
  77. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  78. {
  79. uint32_t low = offset & 0xffffffff;
  80. uint32_t high = offset >> 32;
  81. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  82. }
  83. strong_alias(__libc_pwrite64,pwrite64)
  84. #endif /* __UCLIBC_HAS_LFS__ */
  85. #endif /* !__mips64 */
  86. #endif /* __NR_pwrite */