pread_write.c 3.1 KB

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