bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [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 | #define _LARGEFILE_SOURCE |
| 13 | #define _LARGEFILE64_SOURCE |
| 14 | |
| 15 | #ifdef HAVE_SYS_TYPES_H |
| 16 | #include <sys/types.h> |
| 17 | #endif |
| 18 | |
| 19 | #ifdef HAVE_ERRNO_H |
| 20 | #include <errno.h> |
| 21 | #endif |
| 22 | #ifdef HAVE_UNISTD_H |
| 23 | #include <unistd.h> |
| 24 | #endif |
| 25 | #ifdef __MSDOS__ |
| 26 | #include <io.h> |
| 27 | #endif |
| 28 | |
| 29 | #include "blkidP.h" |
| 30 | |
| 31 | #ifdef __linux__ |
| 32 | |
| 33 | #define my_llseek lseek64 |
| 34 | #include <linux/unistd.h> |
| 35 | |
| 36 | #ifndef __NR__llseek |
| 37 | #define __NR__llseek 140 |
| 38 | #endif |
| 39 | |
| 40 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence) |
| 41 | { |
| 42 | blkid_loff_t result; |
| 43 | static int do_compat = 0; |
| 44 | |
| 45 | if ((sizeof(off_t) >= sizeof(blkid_loff_t)) || |
| 46 | (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1)))) |
| 47 | return lseek(fd, (off_t) offset, whence); |
| 48 | |
| 49 | if (do_compat) { |
| 50 | errno = EOVERFLOW; |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | if (result == -1 && errno == ENOSYS) { |
| 55 | /* |
| 56 | * Just in case this code runs on top of an old kernel |
| 57 | * which does not support the llseek system call |
| 58 | */ |
| 59 | do_compat++; |
| 60 | errno = EOVERFLOW; |
| 61 | } |
| 62 | return result; |
| 63 | } |
| 64 | |
| 65 | #else /* !linux */ |
| 66 | |
| 67 | #ifndef EOVERFLOW |
| 68 | #ifdef EXT2_ET_INVALID_ARGUMENT |
| 69 | #define EOVERFLOW EXT2_ET_INVALID_ARGUMENT |
| 70 | #else |
| 71 | #define EOVERFLOW 112 |
| 72 | #endif |
| 73 | #endif |
| 74 | |
| 75 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int origin) |
| 76 | { |
| 77 | #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) |
| 78 | return lseek64 (fd, offset, origin); |
| 79 | #else |
| 80 | if ((sizeof(off_t) < sizeof(blkid_loff_t)) && |
| 81 | (offset >= ((blkid_loff_t) 1 << ((sizeof(off_t)*8) - 1)))) { |
| 82 | errno = EOVERFLOW; |
| 83 | return -1; |
| 84 | } |
| 85 | return lseek(fd, (off_t) offset, origin); |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | #endif /* linux */ |
| 90 | |
| 91 | |