2 * llseek.c -- stub calling the llseek system call
4 * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
12 #define _LARGEFILE_SOURCE
13 #define _LARGEFILE64_SOURCE
17 #include <sys/types.h>
34 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
36 #define my_llseek lseek64
38 #elif defined(HAVE_LLSEEK)
41 #ifndef HAVE_LLSEEK_PROTOTYPE
42 extern long long llseek(int fd, long long offset, int origin);
45 #define my_llseek llseek
47 #else /* ! HAVE_LLSEEK */
49 #if SIZEOF_LONG == SIZEOF_LONG_LONG
53 #else /* SIZEOF_LONG != SIZEOF_LONG_LONG */
55 #include <linux/unistd.h>
58 #define __NR__llseek 140
62 static int _llseek(unsigned int, unsigned long, unsigned long,
63 blkid_loff_t *, unsigned int);
65 static _syscall5(int, _llseek, unsigned int, fd, unsigned long, offset_high,
66 unsigned long, offset_low, blkid_loff_t *, result,
70 static blkid_loff_t my_llseek(int fd, blkid_loff_t offset, int origin)
76 retval = _llseek(fd, ((unsigned long long) offset) >> 32,
77 ((unsigned long long)offset) & 0xffffffff,
80 retval = syscall(__NR__llseek, fd, ((unsigned long long) offset) >> 32,
81 ((unsigned long long)offset) & 0xffffffff,
84 return (retval == -1 ? (blkid_loff_t) retval : result);
87 #endif /* __alpha__ || __ia64__ */
89 #endif /* HAVE_LLSEEK */
91 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence)
94 static int do_compat = 0;
96 if ((sizeof(off_t) >= sizeof(blkid_loff_t)) ||
97 (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1))))
98 return lseek(fd, (off_t) offset, whence);
105 result = my_llseek(fd, offset, whence);
106 if (result == -1 && errno == ENOSYS) {
108 * Just in case this code runs on top of an old kernel
109 * which does not support the llseek system call
120 #ifdef EXT2_ET_INVALID_ARGUMENT
121 #define EOVERFLOW EXT2_ET_INVALID_ARGUMENT
123 #define EOVERFLOW 112
127 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int origin)
129 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
130 return lseek64 (fd, offset, origin);
132 if ((sizeof(off_t) < sizeof(blkid_loff_t)) &&
133 (offset >= ((blkid_loff_t) 1 << ((sizeof(off_t)*8) - 1)))) {
137 return lseek(fd, (off_t) offset, origin);