home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / disk-utils / llseek.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  1.9 KB  |  85 lines

  1. /*
  2.  * llseek.c -- stub calling the llseek system call
  3.  *
  4.  * Copyright (C) 1994 Remy Card.  This file may be redistributed
  5.  * under the terms of the GNU Public License.
  6.  */
  7.  
  8. #include <sys/types.h>
  9.  
  10. #include <errno.h>
  11. #include <unistd.h>
  12. #include <linux/unistd.h>
  13. #if 0
  14. #include "et/com_err.h"
  15. #include "ext2fs/io.h"
  16. #endif
  17.  
  18. #if defined(__GNUC__) || defined(HAS_LONG_LONG)
  19. typedef long long ext2_loff_t;
  20. #else
  21. typedef long      ext2_loff_t;
  22. #endif
  23.  
  24. extern ext2_loff_t ext2_llseek(unsigned int fd,
  25.                    ext2_loff_t offset,
  26.                    unsigned int origin);
  27.  
  28. #ifdef __linux__
  29.  
  30. #ifndef __NR__llseek
  31. #define __NR__llseek            140
  32. #endif
  33.  
  34. static int _llseek (unsigned int, unsigned long,
  35.            unsigned long, ext2_loff_t *, unsigned int);
  36.  
  37. static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
  38.          unsigned long, offset_low,ext2_loff_t *,result,
  39.          unsigned int, origin)
  40.  
  41. ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
  42.              unsigned int origin)
  43. {
  44.     unsigned long offset_high;
  45.     unsigned long offset_low;
  46.     ext2_loff_t result;
  47.     int retval;
  48.     static int do_compat = 0;
  49.  
  50.     if (do_compat)
  51.         return lseek (fd, (off_t) offset, origin);
  52.     
  53.     offset_high = ((unsigned long long) offset) >> 32;
  54.     offset_low = ((unsigned long long) offset) & 0xffffffff;
  55.     retval = _llseek (fd, offset_high, offset_low, &result, origin);
  56.     if (retval == -1 && errno == ENOSYS) {
  57.         /*
  58.          * Just in case this code runs on top of an old kernel
  59.          * which does not support the llseek system call
  60.          */
  61.         do_compat++;
  62.         return lseek (fd, (off_t) offset, origin);
  63.     }
  64.     if (retval == -1)
  65.         result = -1;
  66.     return result;
  67. }
  68.  
  69. #else
  70.  
  71. ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
  72.              unsigned int origin)
  73. {
  74.     if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
  75.         (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
  76.         errno = -EINVAL;
  77.         return -1;
  78.     }
  79.     return lseek (fd, (off_t) offset, origin);
  80. }
  81.  
  82. #endif
  83.  
  84.  
  85.