From: Andrei Tatar Date: Tue, 18 Mar 2025 16:43:38 +0000 (+0100) Subject: lib/posix-fdio: Fix lseek relative from file end X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=43829daf760ea73fb7d03a18e60c1a8590ec07d9;p=unikraft%2Funikraft.git lib/posix-fdio: Fix lseek relative from file end This change fixes a bug in lseek where the file cursor was always set to the end of file on SEEK_END, ignoring any passed-in offset. Signed-off-by: Andrei Tatar Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1602 --- diff --git a/lib/posix-fdio/fdio.c b/lib/posix-fdio/fdio.c index 0d4b50b5c..ea07b6480 100644 --- a/lib/posix-fdio/fdio.c +++ b/lib/posix-fdio/fdio.c @@ -417,12 +417,17 @@ off_t uk_sys_lseek(struct uk_ofile *of, off_t offset, int whence) _of_lock(of); if (whence == SEEK_END) { const struct uk_file *f = of->file; + ssize_t eof; if (iolock) uk_file_rlock(f); - offset = fdio_get_eof(f); + eof = fdio_get_eof(f); if (iolock) uk_file_runlock(f); + if (eof >= 0) + offset += eof; + else + offset = eof; } else if (whence == SEEK_CUR) { offset += of->pos; }