diff options
-rw-r--r-- | e2fsprogs/blkid/llseek.c | 90 | ||||
-rw-r--r-- | e2fsprogs/ext2fs/llseek.c | 91 |
2 files changed, 9 insertions, 172 deletions
diff --git a/e2fsprogs/blkid/llseek.c b/e2fsprogs/blkid/llseek.c index b5dde03cf..82388dd63 100644 --- a/e2fsprogs/blkid/llseek.c +++ b/e2fsprogs/blkid/llseek.c | |||
@@ -19,70 +19,14 @@ | |||
19 | #if HAVE_UNISTD_H | 19 | #if HAVE_UNISTD_H |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #endif | 21 | #endif |
22 | #ifdef __MSDOS__ | ||
23 | #include <io.h> | ||
24 | #endif | ||
25 | 22 | ||
26 | #include "blkidP.h" | 23 | #include "blkidP.h" |
27 | 24 | ||
28 | #ifdef __linux__ | 25 | #ifdef CONFIG_LFS |
29 | 26 | # define my_llseek lseek64 | |
30 | #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) | ||
31 | |||
32 | #define my_llseek lseek64 | ||
33 | |||
34 | #elif defined(HAVE_LLSEEK) | ||
35 | #include <syscall.h> | ||
36 | |||
37 | #ifndef HAVE_LLSEEK_PROTOTYPE | ||
38 | extern long long llseek(int fd, long long offset, int origin); | ||
39 | #endif | ||
40 | |||
41 | #define my_llseek llseek | ||
42 | |||
43 | #else /* ! HAVE_LLSEEK */ | ||
44 | |||
45 | #if defined(__alpha__) || defined(__ia64__) | ||
46 | |||
47 | #define llseek lseek | ||
48 | |||
49 | #else /* !__alpha__ && !__ia64__*/ | ||
50 | |||
51 | #include <linux/unistd.h> | ||
52 | |||
53 | #ifndef __NR__llseek | ||
54 | #define __NR__llseek 140 | ||
55 | #endif | ||
56 | |||
57 | #ifndef __i386__ | ||
58 | static int _llseek(unsigned int, unsigned long, unsigned long, | ||
59 | blkid_loff_t *, unsigned int); | ||
60 | |||
61 | static _syscall5(int, _llseek, unsigned int, fd, unsigned long, offset_high, | ||
62 | unsigned long, offset_low, blkid_loff_t *, result, | ||
63 | unsigned int, origin) | ||
64 | #endif | ||
65 | |||
66 | static blkid_loff_t my_llseek(int fd, blkid_loff_t offset, int origin) | ||
67 | { | ||
68 | blkid_loff_t result; | ||
69 | int retval; | ||
70 | |||
71 | #ifndef __i386__ | ||
72 | retval = _llseek(fd, ((unsigned long long) offset) >> 32, | ||
73 | ((unsigned long long)offset) & 0xffffffff, | ||
74 | &result, origin); | ||
75 | #else | 27 | #else |
76 | retval = syscall(__NR__llseek, fd, ((unsigned long long) offset) >> 32, | 28 | # define my_llseek lseek |
77 | ((unsigned long long)offset) & 0xffffffff, | ||
78 | &result, origin); | ||
79 | #endif | 29 | #endif |
80 | return (retval == -1 ? (blkid_loff_t) retval : result); | ||
81 | } | ||
82 | |||
83 | #endif /* __alpha__ || __ia64__ */ | ||
84 | |||
85 | #endif /* HAVE_LLSEEK */ | ||
86 | 30 | ||
87 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence) | 31 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence) |
88 | { | 32 | { |
@@ -109,31 +53,3 @@ blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence) | |||
109 | } | 53 | } |
110 | return result; | 54 | return result; |
111 | } | 55 | } |
112 | |||
113 | #else /* !linux */ | ||
114 | |||
115 | #ifndef EOVERFLOW | ||
116 | #ifdef EXT2_ET_INVALID_ARGUMENT | ||
117 | #define EOVERFLOW EXT2_ET_INVALID_ARGUMENT | ||
118 | #else | ||
119 | #define EOVERFLOW 112 | ||
120 | #endif | ||
121 | #endif | ||
122 | |||
123 | blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int origin) | ||
124 | { | ||
125 | #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) | ||
126 | return lseek64 (fd, offset, origin); | ||
127 | #else | ||
128 | if ((sizeof(off_t) < sizeof(blkid_loff_t)) && | ||
129 | (offset >= ((blkid_loff_t) 1 << ((sizeof(off_t)*8) - 1)))) { | ||
130 | errno = EOVERFLOW; | ||
131 | return -1; | ||
132 | } | ||
133 | return lseek(fd, (off_t) offset, origin); | ||
134 | #endif | ||
135 | } | ||
136 | |||
137 | #endif /* linux */ | ||
138 | |||
139 | |||
diff --git a/e2fsprogs/ext2fs/llseek.c b/e2fsprogs/ext2fs/llseek.c index 502faa3dd..6bb84bf09 100644 --- a/e2fsprogs/ext2fs/llseek.c +++ b/e2fsprogs/ext2fs/llseek.c | |||
@@ -4,8 +4,8 @@ | |||
4 | * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o. | 4 | * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o. |
5 | * | 5 | * |
6 | * %Begin-Header% | 6 | * %Begin-Header% |
7 | * This file may be redistributed under the terms of the GNU Public | 7 | * This file may be redistributed under the terms of the |
8 | * License. | 8 | * GNU Lesser General Public License. |
9 | * %End-Header% | 9 | * %End-Header% |
10 | */ | 10 | */ |
11 | 11 | ||
@@ -19,69 +19,14 @@ | |||
19 | #if HAVE_UNISTD_H | 19 | #if HAVE_UNISTD_H |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #endif | 21 | #endif |
22 | #ifdef __MSDOS__ | ||
23 | #include <io.h> | ||
24 | #endif | ||
25 | #include "ext2fs/ext2_io.h" | ||
26 | |||
27 | #ifdef __linux__ | ||
28 | 22 | ||
29 | #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) | 23 | #include "ext2fs/ext2_io.h" |
30 | |||
31 | #define my_llseek lseek64 | ||
32 | 24 | ||
25 | #ifdef CONFIG_LFS | ||
26 | # define my_llseek lseek64 | ||
33 | #else | 27 | #else |
34 | #if defined(HAVE_LLSEEK) | 28 | # define my_llseek lseek |
35 | #include <syscall.h> | ||
36 | |||
37 | #ifndef HAVE_LLSEEK_PROTOTYPE | ||
38 | extern long long llseek (int fd, long long offset, int origin); | ||
39 | #endif | ||
40 | |||
41 | #define my_llseek llseek | ||
42 | |||
43 | #else /* ! HAVE_LLSEEK */ | ||
44 | |||
45 | #if defined(__alpha__) || defined (__ia64__) | ||
46 | |||
47 | #define llseek lseek | ||
48 | |||
49 | #else /* !__alpha__ && !__ia64__*/ | ||
50 | |||
51 | #include <linux/unistd.h> | ||
52 | |||
53 | #ifndef __NR__llseek | ||
54 | #define __NR__llseek 140 | ||
55 | #endif | ||
56 | |||
57 | #ifndef __i386__ | ||
58 | static int _llseek (unsigned int, unsigned long, | ||
59 | unsigned long, ext2_loff_t *, unsigned int); | ||
60 | |||
61 | static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high, | ||
62 | unsigned long, offset_low,ext2_loff_t *,result, | ||
63 | unsigned int, origin) | ||
64 | #endif | ||
65 | |||
66 | static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin) | ||
67 | { | ||
68 | ext2_loff_t result; | ||
69 | int retval; | ||
70 | |||
71 | #ifndef __i386__ | ||
72 | retval = _llseek(fd, ((unsigned long long) offset) >> 32, | ||
73 | #else | ||
74 | retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32), | ||
75 | #endif | 29 | #endif |
76 | ((unsigned long long) offset) & 0xffffffff, | ||
77 | &result, origin); | ||
78 | return (retval == -1 ? (ext2_loff_t) retval : result); | ||
79 | } | ||
80 | |||
81 | #endif /* __alpha__ || __ia64__ */ | ||
82 | |||
83 | #endif /* HAVE_LLSEEK */ | ||
84 | #endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */ | ||
85 | 30 | ||
86 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) | 31 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) |
87 | { | 32 | { |
@@ -108,27 +53,3 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) | |||
108 | } | 53 | } |
109 | return result; | 54 | return result; |
110 | } | 55 | } |
111 | |||
112 | #else /* !linux */ | ||
113 | |||
114 | #ifndef EINVAL | ||
115 | #define EINVAL EXT2_ET_INVALID_ARGUMENT | ||
116 | #endif | ||
117 | |||
118 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) | ||
119 | { | ||
120 | #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) | ||
121 | return lseek64 (fd, offset, origin); | ||
122 | #else | ||
123 | if ((sizeof(off_t) < sizeof(ext2_loff_t)) && | ||
124 | (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) { | ||
125 | errno = EINVAL; | ||
126 | return -1; | ||
127 | } | ||
128 | return lseek (fd, (off_t) offset, origin); | ||
129 | #endif | ||
130 | } | ||
131 | |||
132 | #endif /* linux */ | ||
133 | |||
134 | |||