Re: Programming in standard c
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Dec 2007 09:02:21 -0500
Richard wrote:
user923005 <dcorbit@xxxxxxxxx> writes:[...]
a generic function cannot produce a reliable answer. I guess that
other people have thought about this question and figured out that a
reliable file size function cannot be written in a generic manner.
Rubbish. All files have a byte size.
How many bytes does /dev/tty hold? How about /dev/zero?
/dev/ptyp0? /dev/random? /dev/poll? CON:? LPT:?
Noone has ever said this. A portable file size function that gives a
correct answer is clearly impossible.
How silly.
"correct" would be platform specific. The API need not be.
One could assign an arbitrary pseudo-size -- minus one,
perhaps -- to the troublesome files, and then declare that
this pseudo-size was the "correct by decree" size of the
file. However, the value would then be useless for the
purpose to which Jacob's "Happy christmas" code wanted: to
determine how many bytes to allocate to hold the file's
content.
And even for an ordinary file whose length can be known,
many systems permit the length to change between the moment
it's queried and the moment the result is used. How many bytes
should you allocate for an in-memory copy of /var/adm/messages?
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Programming in standard c
- From: Serve La
- Re: Programming in standard c
- From: Bart C
- Re: Programming in standard c
- References:
- Programming in standard c
- From: jacob navia
- Re: Programming in standard c
- From: jameskuyper
- Re: Programming in standard c
- From: Erik Trulsson
- Re: Programming in standard c
- From: user923005
- Re: Programming in standard c
- From: jacob navia
- Re: Programming in standard c
- From: Richard Heathfield
- Re: Programming in standard c
- From: jacob navia
- Re: Programming in standard c
- From: user923005
- Re: Programming in standard c
- From: Richard
- Programming in standard c
- Prev by Date: Re: Programming in standard c
- Next by Date: Re: Programming in standard c
- Previous by thread: Re: Programming in standard c
- Next by thread: Re: Programming in standard c
- Index(es):
Relevant Pages
|