From 20d769da8ed8b88e0be05ec6617fe7c8b404be5f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 14 Dec 2017 11:56:11 +0000 Subject: [PATCH] syscall_fs: diet lseek another 80 bytes or so --- Kernel/syscall_fs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Kernel/syscall_fs.c b/Kernel/syscall_fs.c index 0fe1bf61..aa49f8f9 100644 --- a/Kernel/syscall_fs.c +++ b/Kernel/syscall_fs.c @@ -25,10 +25,12 @@ void updoff(void) as a 32bit OS might */ arg_t _lseek(void) { + static off_t zero; inoptr ino; struct oft *o; off_t p; off_t n; + off_t *pt; if (uget(offset, &n, sizeof(n))) return -1; @@ -44,15 +46,21 @@ arg_t _lseek(void) o = &of_tab[udata.u_files[file]]; p = o->o_ptr; + /* 32bit maths is really messy on some processors and the three cases + produce three sets of 32bit maths operations. Instead we take a + pointer to what to use as the offset and do the maths once */ + if (flag == 0) - p = n; + pt = &zero; else if (flag == 1) - p += n; + pt = &p; else if (flag == 2) - p = ino->c_node.i_size + n; + pt = &ino->c_node.i_size; else goto bad; + p = *pt + n; + if (p < 0) goto bad; -- 2.34.1