pread_write.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #define __NR___syscall_pread __NR_pread
  36. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  37. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  38. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  39. {
  40. return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR((off_t)0,offset)));
  41. }
  42. strong_alias(__libc_pread,pread)
  43. #if defined __UCLIBC_HAS_LFS__
  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. strong_alias(__libc_pread64,pread64)
  51. #endif /* __UCLIBC_HAS_LFS__ */
  52. #endif /* __NR_pread */
  53. /**********************************************************************/
  54. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  55. # ifdef __NR_pwrite
  56. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  57. # endif
  58. # define __NR_pwrite __NR_pwrite64
  59. #endif
  60. #ifdef __NR_pwrite
  61. #define __NR___syscall_pwrite __NR_pwrite
  62. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  63. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  64. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  65. {
  66. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR((off_t)0,offset)));
  67. }
  68. strong_alias(__libc_pwrite,pwrite)
  69. #if defined __UCLIBC_HAS_LFS__
  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. strong_alias(__libc_pwrite64,pwrite64)
  77. #endif /* __UCLIBC_HAS_LFS__ */
  78. #endif /* __NR_pwrite */