public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Avoid ARM SWI Seek when querying file position Date: Mon, 03 Sep 2018 07:42:00 -0000 [thread overview] Message-ID: <20180903074230.128836.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3017f23f1cfdf31dbebdeaa32e45aca15c0b77b6 commit 3017f23f1cfdf31dbebdeaa32e45aca15c0b77b6 Author: Andy Koppe <andy.koppe@gmail.com> Date: Fri Aug 31 12:26:02 2018 +0100 Avoid ARM SWI Seek when querying file position Issuing an ARM semi-hosting Seek command when just querying file position with SEEK_CUR and offset zero is unnecessary, because unlike the lseek() Unix system call the Seek command does not actually return the file position. For that reason, syscalls.c for ARM keeps track of file position in the 'poslog', so we can just return that. Moreover, since the Seek command only accepts an absolute file position, SEEK_CUR operations are implemented by adding the relative offset to the position in the poslog. If the host implements non-binary files with implicit carriage return characters but doesn't discount those implicit CRs when implementing Seek (by just mapping straight to Windows file operations), this actually ended up wrongly changing file position when using SEEK_CUR with offset zero or functions like ftell() or fgetpos() that are based on that. Also, use off_t rather than int for the poslog. Diff: --- newlib/libc/sys/arm/syscalls.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c index e0cf0ac..6e70467 100644 --- a/newlib/libc/sys/arm/syscalls.c +++ b/newlib/libc/sys/arm/syscalls.c @@ -76,7 +76,7 @@ static int monitor_stderr; typedef struct { int handle; - int pos; + off_t pos; } poslog; @@ -234,9 +234,16 @@ _swilseek (int file, off_t ptr, int dir) if (dir == SEEK_CUR) { + off_t pos; if (slot == MAX_OPEN_FILES) return -1; - ptr = openfiles[slot].pos + ptr; + pos = openfiles[slot].pos; + + /* Avoid SWI SEEK command when just querying file position. */ + if (ptr == 0) + return pos; + + ptr += pos; dir = SEEK_SET; }
reply other threads:[~2018-09-03 7:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180903074230.128836.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).