pread_write.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. # define __NR___syscall_pread __NR_pread
  25. static inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf,
  26. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  27. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  28. {
  29. return(__syscall_pread(fd,buf,count,0,__LONG_LONG_PAIR((off_t)0,offset)));
  30. }
  31. weak_alias(__libc_pread,pread)
  32. # ifdef __UCLIBC_HAS_LFS__
  33. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  34. {
  35. uint32_t low = offset & 0xffffffff;
  36. uint32_t high = offset >> 32;
  37. return(__syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  38. }
  39. weak_alias(__libc_pread64,pread64)
  40. # endif /* __UCLIBC_HAS_LFS__ */
  41. #endif /* __NR_pread */
  42. /**********************************************************************/
  43. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  44. # ifdef __NR_pwrite
  45. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  46. # endif
  47. # define __NR_pwrite __NR_pwrite64
  48. #endif
  49. #ifdef __NR_pwrite
  50. # define __NR___syscall_pwrite __NR_pwrite
  51. static inline _syscall6(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  52. size_t, count, int, dummy, off_t, offset_hi, off_t, offset_lo);
  53. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  54. {
  55. return(__syscall_pwrite(fd,buf,count,0,__LONG_LONG_PAIR((off_t)0,offset)));
  56. }
  57. weak_alias(__libc_pwrite,pwrite)
  58. # ifdef __UCLIBC_HAS_LFS__
  59. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  60. {
  61. uint32_t low = offset & 0xffffffff;
  62. uint32_t high = offset >> 32;
  63. return(__syscall_pwrite(fd, buf, count, 0, __LONG_LONG_PAIR (high, low)));
  64. }
  65. weak_alias(__libc_pwrite64,pwrite64)
  66. # endif /* __UCLIBC_HAS_LFS__ */
  67. #endif /* __NR_pwrite */