Mike Frysinger | 38a33f9 | 2005-05-09 22:13:22 +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% |
| 7 | * This file may be redistributed under the terms of the |
| 8 | * GNU Lesser General Public License. |
| 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 | 38a33f9 | 2005-05-09 22:13:22 +0000 | [diff] [blame] | 22 | |
| 23 | #include "blkidP.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 | 38a33f9 | 2005-05-09 22:13:22 +0000 | [diff] [blame] | 27 | #else |
Mike Frysinger | fc379ba | 2005-06-28 23:50:18 +0000 | [diff] [blame^] | 28 | # define my_llseek lseek |
Mike Frysinger | 38a33f9 | 2005-05-09 22:13:22 +0000 | [diff] [blame] | 29 | #endif |
Mike Frysinger | 38a33f9 | 2005-05-09 22:13:22 +0000 | [diff] [blame] | 30 | |
| 31 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence) |
| 32 | { |
| 33 | blkid_loff_t result; |
| 34 | static int do_compat = 0; |
| 35 | |
| 36 | if ((sizeof(off_t) >= sizeof(blkid_loff_t)) || |
| 37 | (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1)))) |
| 38 | return lseek(fd, (off_t) offset, whence); |
| 39 | |
| 40 | if (do_compat) { |
| 41 | errno = EOVERFLOW; |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | result = my_llseek(fd, offset, whence); |
| 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 = EOVERFLOW; |
| 53 | } |
| 54 | return result; |
| 55 | } |