Re: fseek past the eof
From: Chris Croughton (chris_at_keristor.net)
Date: 11/30/04
- Next message: Chris Croughton: "Re: How do you read source for big programs?"
- Previous message: Chris Croughton: "Re: simple file system"
- In reply to: Richard Bos: "Re: fseek past the eof"
- Next in thread: Dan Pop: "Re: fseek past the eof"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Nov 2004 10:55:40 +0000
On Tue, 30 Nov 2004 07:45:09 GMT, Richard Bos
<rlb@hoekstra-uitgeverij.nl> wrote:
> "Xenos" <dont.spam.me@spamhate.com> wrote:
>
>> Can anyone tell me what the standard says about using fseek (on a binary
>> file) to seek past the end-of-file?
>
> Nothing, AFAICT. Which means that, unless I missed something, it's
> undefined behaviour. Which is odd; I'd have expected it to be
> unspecified: either return non-zero from fseek(), or allow it and do
> something system-specific but non-crashing to the file.
I hadn't realised that either. It doesn't even say that the behaviour
is undefined or implementation defined (although some implementations of
the library do define it, for instance on many Unix systems where it
allows writes (but not reads) past the end of file leaving 'holes').
For that matter since the type of the offset is (signed) long int it is
theoretically valid to use a negative number with SEEK_SET.
POSIX.1 does specify the action for writing beyond end of file, if one
is using a POSIX-compliant system:
The fseek() function shall allow the file-position indicator to be
set beyond the end of existing data in the file. If data is later
written at this point, subsequent reads of data in the gap shall
return bytes with the value 0 until data is actually written into
the gap.
Chris C
- Next message: Chris Croughton: "Re: How do you read source for big programs?"
- Previous message: Chris Croughton: "Re: simple file system"
- In reply to: Richard Bos: "Re: fseek past the eof"
- Next in thread: Dan Pop: "Re: fseek past the eof"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]