Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorAndy Koppe <andy.koppe@gmail.com>2018-08-31 14:26:02 +0300
committerCorinna Vinschen <corinna@vinschen.de>2018-09-03 10:40:39 +0300
commit3017f23f1cfdf31dbebdeaa32e45aca15c0b77b6 (patch)
treec0cb76bf837efc798dfcadcbd89cbd24ffeb4973 /newlib
parentd1454de7b03c93556c33c33c5fd8db288ab4feac (diff)
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.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/sys/arm/syscalls.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c
index e0cf0ac65..6e70467ea 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;
}