This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: fgetpos/ftello without system call
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>, libc-help <libc-help at sourceware dot org>
- Date: Fri, 1 Sep 2017 07:59:11 -0500
- Subject: Re: fgetpos/ftello without system call
- Authentication-results: sourceware.org; auth=none
- References: <6ae5f3c9-58e3-d080-6103-a3bd3965bdfe@redhat.com>
On 09/01/2017 04:17 AM, Florian Weimer wrote:
> Is it possible to obtain the current read offset of a stream without
> triggering an lseek system call?
Hard to say without looking at a very specific use case.
The answer to that is actually incredibly complicated, and requires a
table (which may now be out of date), and a bunch of rules from POSIX:
https://sourceware.org/glibc/wiki/File%20offsets%20in%20a%20stdio%20stream%20and%20ftell
> I know that nothing manipulates the underlying file descriptor directly.
That's good, because otherwise you *would* need a seek to allow the active
handle to change between the fd and the FILE* as required by POSIX.
> The actual goal here is to read the same line multiple times using
> fgets, enlarging the buffer if necessary.
You should be able to do that, and it shouldn't trigger a seek.
> It seems that libio maintains an _offset member in the underlying FILE
> object, but never actually uses it for descriptor-based files (mapped
> files are a different story).
It should.
--
Cheers,
Carlos.