pread_write.c 2.5 KB

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