[PATCH] Avoid ARM SWI Seek when querying file position
Andy Koppe
andy.koppe@gmail.com
Fri Aug 31 16:48:00 GMT 2018
On 31 August 2018 at 12:10, Andy Koppe wrote:
> 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.
>
> The ARM semi-hosting Seek command is documented at
> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0040d/BACDFGCG.html
>
> (There's a wider problem in that using the position returned by the
> likes of ftell() in a later seek operation gets you to the wrong place
> if the host adds implicit CRs without discounting them in Seek
> commands. Not sure there's anything that can be done about it on the
> newlib side though.)
Slightly amended patch attached: Use off_t rather than int for the poslog.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Avoid-ARM-SWI-Seek-when-querying-file-position.patch
Type: application/octet-stream
Size: 1936 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20180831/10328716/attachment.obj>
More information about the Newlib
mailing list