Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 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% |
Mike Frysinger | fc379ba | 2005-06-28 23:50:18 +0000 | [diff] [blame] | 7 | * This file may be redistributed under the terms of the |
| 8 | * GNU Lesser General Public License. |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 9 | * %End-Header% |
| 10 | */ |
| 11 | |
| 12 | #if HAVE_SYS_TYPES_H |
| 13 | #include <sys/types.h> |
| 14 | #endif |
| 15 | |
| 16 | #if HAVE_ERRNO_H |
| 17 | #include <errno.h> |
| 18 | #endif |
| 19 | #if HAVE_UNISTD_H |
| 20 | #include <unistd.h> |
| 21 | #endif |
Mike Frysinger | fc379ba | 2005-06-28 23:50:18 +0000 | [diff] [blame] | 22 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 23 | #include "ext2fs/ext2_io.h" |
| 24 | |
Mike Frysinger | fc379ba | 2005-06-28 23:50:18 +0000 | [diff] [blame] | 25 | #ifdef CONFIG_LFS |
| 26 | # define my_llseek lseek64 |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 27 | #else |
Mike Frysinger | fc379ba | 2005-06-28 23:50:18 +0000 | [diff] [blame] | 28 | # define my_llseek lseek |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 31 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) |
| 32 | { |
| 33 | ext2_loff_t result; |
| 34 | static int do_compat = 0; |
| 35 | |
| 36 | if ((sizeof(off_t) >= sizeof(ext2_loff_t)) || |
| 37 | (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) |
| 38 | return lseek(fd, (off_t) offset, origin); |
| 39 | |
| 40 | if (do_compat) { |
| 41 | errno = EINVAL; |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | result = my_llseek (fd, offset, origin); |
| 46 | if (result == -1 && errno == ENOSYS) { |
| 47 | /* |
| 48 | * Just in case this code runs on top of an old kernel |
| 49 | * which does not support the llseek system call |
| 50 | */ |
| 51 | do_compat++; |
| 52 | errno = EINVAL; |
| 53 | } |
| 54 | return result; |
| 55 | } |