llseek.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * llseek/lseek64 syscall for uClibc
  4. *
  5. * Copyright (C) 2002 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Library General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #define _GNU_SOURCE
  23. #define _LARGEFILE64_SOURCE
  24. #include <features.h>
  25. #undef __OPTIMIZE__
  26. /* We absolutely do _NOT_ want interfaces silently
  27. * renamed under us or very bad things will happen... */
  28. #ifdef __USE_FILE_OFFSET64
  29. # undef __USE_FILE_OFFSET64
  30. #endif
  31. #include <errno.h>
  32. #include <sys/types.h>
  33. #include <sys/syscall.h>
  34. #undef lseek64
  35. #if defined __NR__llseek && defined __UCLIBC_HAS_LFS__
  36. #ifndef INLINE_SYSCALL
  37. #define INLINE_SYSCALL(name, nr, args...) __syscall_llseek (args)
  38. #define __NR___syscall_llseek __NR__llseek
  39. static inline _syscall5(int, __syscall_llseek, int, fd, off_t, offset_hi,
  40. off_t, offset_lo, loff_t *, result, int, whence);
  41. #endif
  42. loff_t attribute_hidden __lseek64(int fd, loff_t offset, int whence)
  43. {
  44. loff_t result;
  45. return(loff_t)(INLINE_SYSCALL (_llseek, 5, fd, (off_t) (offset >> 32),
  46. (off_t) (offset & 0xffffffff), &result, whence) ?: result);
  47. }
  48. #else
  49. extern __off_t __lseek(int fildes, off_t offset, int whence) attribute_hidden;
  50. loff_t __lseek64(int fd, loff_t offset, int whence)
  51. {
  52. return(loff_t)(__lseek(fd, (off_t) (offset & 0xffffffff), whence));
  53. }
  54. #endif
  55. strong_alias(__lseek64,lseek64)
  56. //strong_alias(__lseek64,_llseek)
  57. //strong_alias(__lseek64,llseek)
  58. weak_alias(__lseek64,__libc_lseek64)