3
0

llseek.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * llseek.c -- stub calling the llseek system call
  3. *
  4. * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
  5. *
  6. * %Begin-Header%
  7. * This file may be redistributed under the terms of the
  8. * GNU Lesser General Public License.
  9. * %End-Header%
  10. */
  11. #if HAVE_SYS_TYPES_H
  12. #include <sys/types.h>
  13. #endif
  14. #if HAVE_ERRNO_H
  15. #include <errno.h>
  16. #endif
  17. #if HAVE_UNISTD_H
  18. #include <unistd.h>
  19. #endif
  20. #include "blkidP.h"
  21. #ifdef CONFIG_LFS
  22. # define my_llseek lseek64
  23. #else
  24. # define my_llseek lseek
  25. #endif
  26. blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence)
  27. {
  28. blkid_loff_t result;
  29. static int do_compat = 0;
  30. if ((sizeof(off_t) >= sizeof(blkid_loff_t)) ||
  31. (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1))))
  32. return lseek(fd, (off_t) offset, whence);
  33. if (do_compat) {
  34. errno = EOVERFLOW;
  35. return -1;
  36. }
  37. result = my_llseek(fd, offset, whence);
  38. if (result == -1 && errno == ENOSYS) {
  39. /*
  40. * Just in case this code runs on top of an old kernel
  41. * which does not support the llseek system call
  42. */
  43. do_compat++;
  44. errno = EOVERFLOW;
  45. }
  46. return result;
  47. }