pread_write.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* vi: set sw=4 ts=4:
  2. *
  3. * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
  4. * Based in part on the files
  5. * ./sysdeps/unix/sysv/linux/pwrite.c,
  6. * ./sysdeps/unix/sysv/linux/pread.c,
  7. * sysdeps/posix/pread.c
  8. * sysdeps/posix/pwrite.c
  9. * from GNU libc 2.2.5, but reworked considerably...
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU Library General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  19. * for more details.
  20. *
  21. * You should have received a copy of the GNU Library General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #define _LARGEFILE64_SOURCE
  26. #include <features.h>
  27. #undef __OPTIMIZE__
  28. /* We absolutely do _NOT_ want interfaces silently
  29. * * * renamed under us or very bad things will happen... */
  30. #ifdef __USE_FILE_OFFSET64
  31. # undef __USE_FILE_OFFSET64
  32. #endif
  33. #include <errno.h>
  34. #include <sys/types.h>
  35. #include <sys/syscall.h>
  36. #include <unistd.h>
  37. #include <stdint.h>
  38. extern __typeof(pread) __libc_pread;
  39. extern __typeof(pwrite) __libc_pwrite;
  40. #ifdef __UCLIBC_HAS_LFS__
  41. extern __typeof(pread64) __libc_pread64;
  42. extern __typeof(pwrite64) __libc_pwrite64;
  43. #endif
  44. #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
  45. # ifdef __NR_pread
  46. # error "__NR_pread and __NR_pread64 both defined???"
  47. # endif
  48. # define __NR_pread __NR_pread64
  49. #endif
  50. #define __NR___syscall_pread __NR_pread
  51. static inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
  52. size_t, count, off_t, offset_hi, off_t, offset_lo);
  53. ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset)
  54. {
  55. return(__syscall_pread(fd,buf,count,offset,offset >> 31));
  56. }
  57. weak_alias (__libc_pread, pread)
  58. #if defined __UCLIBC_HAS_LFS__
  59. ssize_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset)
  60. {
  61. uint32_t low = offset & 0xffffffff;
  62. uint32_t high = offset >> 32;
  63. return(__syscall_pread(fd, buf, count, low, high));
  64. }
  65. weak_alias (__libc_pread64, pread64)
  66. #endif /* __UCLIBC_HAS_LFS__ */
  67. #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
  68. # ifdef __NR_pwrite
  69. # error "__NR_pwrite and __NR_pwrite64 both defined???"
  70. # endif
  71. # define __NR_pwrite __NR_pwrite64
  72. #endif
  73. #define __NR___syscall_pwrite __NR_pwrite
  74. static inline _syscall5(ssize_t, __syscall_pwrite, int, fd, const void *, buf,
  75. size_t, count, off_t, offset_hi, off_t, offset_lo);
  76. ssize_t __libc_pwrite(int fd, const void *buf, size_t count, off_t offset)
  77. {
  78. return(__syscall_pwrite(fd,buf,count,offset,offset >> 31));
  79. }
  80. weak_alias (__libc_pwrite, pwrite)
  81. #if defined __UCLIBC_HAS_LFS__
  82. ssize_t __libc_pwrite64(int fd, const void *buf, size_t count, off64_t offset)
  83. {
  84. uint32_t low = offset & 0xffffffff;
  85. uint32_t high = offset >> 32;
  86. return(__syscall_pwrite(fd, buf, count, low, high));
  87. }
  88. weak_alias (__libc_pwrite64, pwrite64)
  89. #endif /* __UCLIBC_HAS_LFS__ */