[Toybox] ftell/fseek
enh
enh at google.com
Sat Feb 18 20:51:02 PST 2023
on your blog you said:
"""
Oh goddess fsetpos() is a stupid API, isn't it? The classic ftell()
returns long which is signed 32 bits on 32 bit systems, and files are
bigger than that these days, but instead of doing some sort of
lftell() which returns long long (and an lfseek that accepts it) they
invented a new gratuitous fpos_t type which they pretend isn't just a
typedef for "long long", and then created two new libc functions with
completely unrelated names: int fgetpos(FILE *fp, fpos_t *pos) and int
fsetpos(FILE *fp, const fpos_t *pos), both of which are FUCKING
STUPID.
"""
check out fseeko()/ftello() ... they're basically the functions you
were asking for, albeit using off_t rather than "raw" long long.
(funnily enough, although this ought to be irrelevant to most people
in 2023 thanks to LP64 making fseek()/ftell() equivalent to
fseeko()/ftello(), between the low end still being LP32 and the
Windows host being LLP64, i've still had cause to move code over even
in the last few months!)
fwiw, fgetpos()/fsetpos() was the C standards committee's fault ---
they wanted to be able to support systems where file offsets weren't
just integers. presumably the same systems that didn't have 8-bit
bytes and weren't using two's complement :-P
More information about the Toybox
mailing list