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 #ifndef _LARGEFILE_SOURCE
13 #define _LARGEFILE_SOURCE
15 #ifndef _LARGEFILE64_SOURCE
16 #define _LARGEFILE64_SOURCE
21 #include <sys/types.h>
38 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
40 #define my_llseek lseek64
42 #elif defined(HAVE_LLSEEK)
43 #include <sys/syscall.h>
45 #ifndef HAVE_LLSEEK_PROTOTYPE
46 extern long long llseek(int fd, long long offset, int origin);
49 #define my_llseek llseek
51 #else /* ! HAVE_LLSEEK */
53 #if SIZEOF_LONG == SIZEOF_LONG_LONG
57 #else /* SIZEOF_LONG != SIZEOF_LONG_LONG */
59 #include <linux/unistd.h>
62 #define __NR__llseek 140
66 static int _llseek(unsigned int, unsigned long, unsigned long,
67 blkid_loff_t *, unsigned int);
69 static _syscall5(int, _llseek, unsigned int, fd, unsigned long, offset_high,
70 unsigned long, offset_low, blkid_loff_t *, result,
74 static blkid_loff_t my_llseek(int fd, blkid_loff_t offset, int origin)
80 retval = _llseek(fd, ((unsigned long long) offset) >> 32,
81 ((unsigned long long)offset) & 0xffffffff,
84 retval = syscall(__NR__llseek, fd, ((unsigned long long) offset) >> 32,
85 ((unsigned long long)offset) & 0xffffffff,
88 return (retval == -1 ? (blkid_loff_t) retval : result);
91 #endif /* __alpha__ || __ia64__ */
93 #endif /* HAVE_LLSEEK */
95 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence)
98 static int do_compat = 0;
100 if ((sizeof(off_t) >= sizeof(blkid_loff_t)) ||
101 (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1))))
102 return lseek(fd, (off_t) offset, whence);
109 result = my_llseek(fd, offset, whence);
110 if (result == -1 && errno == ENOSYS) {
112 * Just in case this code runs on top of an old kernel
113 * which does not support the llseek system call
124 #ifdef EXT2_ET_INVALID_ARGUMENT
125 #define EOVERFLOW EXT2_ET_INVALID_ARGUMENT
127 #define EOVERFLOW 112
131 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int origin)
133 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
134 return lseek64 (fd, offset, origin);
136 if ((sizeof(off_t) < sizeof(blkid_loff_t)) &&
137 (offset >= ((blkid_loff_t) 1 << ((sizeof(off_t)*8) - 1)))) {
141 return lseek(fd, (off_t) offset, origin);