Skip to content

Commit 24181bb

Browse files
floppymtytso
authored andcommitted
lib/ext2fs: llseek: simplify linux section
On 32-bit musl systems, off_t is always 8 bytes regardless of _FILE_OFFSET_BITS. The previous code did not cover this case. The previous #ifdef logic was rather confusing, so I reworked it into a more understandable form. Bug: https://bugs.gentoo.org/908892 Signed-off-by: Mike Gilbert <floppym@gentoo.org> Closes: #150 Signed-off-by: Sam James <sam@gentoo.org> Link: https://lore.kernel.org/r/20231107233323.2013334-2-sam@gentoo.org Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent fed000a commit 24181bb

1 file changed

Lines changed: 15 additions & 52 deletions

File tree

lib/ext2fs/llseek.c

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,68 +35,32 @@
3535

3636
#ifdef __linux__
3737

38-
#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
39-
40-
#define my_llseek lseek64
41-
42-
#else
43-
#if defined(HAVE_LLSEEK)
44-
#include <sys/syscall.h>
45-
46-
#ifndef HAVE_LLSEEK_PROTOTYPE
47-
extern long long llseek (int fd, long long offset, int origin);
48-
#endif
49-
50-
#define my_llseek llseek
51-
52-
#else /* ! HAVE_LLSEEK */
53-
54-
#if SIZEOF_LONG == SIZEOF_LONG_LONG || _FILE_OFFSET_BITS+0 == 64
55-
56-
#define my_llseek lseek
57-
58-
#else /* SIZEOF_LONG != SIZEOF_LONG_LONG */
59-
6038
#include <linux/unistd.h>
6139

62-
#ifndef __NR__llseek
63-
#define __NR__llseek 140
64-
#endif
65-
66-
#ifndef __i386__
67-
static int _llseek (unsigned int, unsigned long,
68-
unsigned long, ext2_loff_t *, unsigned int);
69-
70-
static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
71-
unsigned long, offset_low,ext2_loff_t *,result,
72-
unsigned int, origin);
73-
#endif
74-
7540
static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
7641
{
77-
ext2_loff_t result;
42+
#if SIZEOF_OFF_T >= 8
43+
return lseek(fd, offset, origin);
44+
#elif HAVE_LSEEK64_PROTOTYPE
45+
return lseek64(fd, offset, origin);
46+
#elif HAVE_LLSEEK_PROTOTYPE
47+
return llseek(fd, offset, origin);
48+
#elif defined(__NR__llseek)
49+
loff_t result;
7850
int retval;
79-
80-
#ifndef __i386__
81-
retval = _llseek(fd, ((unsigned long long) offset) >> 32,
51+
retval = syscall(__NR__llseek, fd,
52+
(unsigned long)(offset >> 32),
53+
(unsigned long)(offset & 0xffffffff),
54+
&result, origin);
55+
return (retval == -1 ? retval : result);
8256
#else
83-
retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32),
57+
errno = ENOSYS;
58+
return -1;
8459
#endif
85-
((unsigned long long) offset) & 0xffffffff,
86-
&result, origin);
87-
return (retval == -1 ? (ext2_loff_t) retval : result);
8860
}
8961

90-
#endif /* SIZE_LONG == SIZEOF_LONG_LONG */
91-
92-
#endif /* HAVE_LLSEEK */
93-
#endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */
94-
9562
ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
9663
{
97-
#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
98-
return my_llseek (fd, offset, origin);
99-
#else
10064
ext2_loff_t result;
10165
static int do_compat = 0;
10266

@@ -117,7 +81,6 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
11781
return -1;
11882
}
11983
return result;
120-
#endif
12184
}
12285

12386
#else /* !linux */

0 commit comments

Comments
 (0)