home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / win95 / ext2tool.exe / EXT2FS / LLSEEK.C < prev    next >
C/C++ Source or Header  |  1995-05-10  |  2KB  |  74 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. #include <errno.h>
  14. #include "com_err.h"
  15. #include "ext2fs/io.h"
  16.  
  17. #ifdef __linux__
  18.  
  19. #ifndef __NR__llseek
  20. #define __NR__llseek            140
  21. #endif
  22.  
  23. static int _llseek (unsigned int, unsigned long,
  24.            unsigned long, ext2_loff_t *, unsigned int);
  25.  
  26. static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
  27.          unsigned long, offset_low,ext2_loff_t *,result,
  28.          unsigned int, origin)
  29.  
  30. ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
  31.              unsigned int origin)
  32. {
  33.     unsigned long offset_high;
  34.     unsigned long offset_low;
  35.     ext2_loff_t result;
  36.     int retval;
  37.     static int do_compat = 0;
  38.  
  39.     if (do_compat)
  40.         return lseek (fd, (off_t) offset, origin);
  41.     
  42.     offset_high = ((unsigned long long) offset) >> 32;
  43.     offset_low = ((unsigned long long) offset) & 0xffffffff;
  44.     retval = _llseek (fd, offset_high, offset_low, &result, origin);
  45.     if (retval == -1 && errno == ENOSYS) {
  46.         /*
  47.          * Just in case this code runs on top of an old kernel
  48.          * which does not support the llseek system call
  49.          */
  50.         do_compat++;
  51.         return lseek (fd, (off_t) offset, origin);
  52.     }
  53.     if (retval == -1)
  54.         result = -1;
  55.     return result;
  56. }
  57.  
  58. #else
  59.  
  60. ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
  61.              unsigned int origin)
  62. {
  63.     if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
  64.         (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
  65.         errno = -EINVAL;
  66.         return -1;
  67.     }
  68.     return lseek (fd, (off_t) offset, origin);
  69. }
  70.  
  71. #endif
  72.  
  73.  
  74.