Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > streams - c standard

Reply
Thread Tools

streams - c standard

 
 
MisterE
Guest
Posts: n/a
 
      10-22-2007
Is there anything in c standard about the operation of file streams etc. in
reguards to how they are supposed to act if an over flow occurs. I am trying
to work out the correct way to handle files that are greater than 2^32
bytes. Different compilers/operating systems etc. all behave different for
ftell. I guess the answer is its undefined...


 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      10-22-2007
"MisterE" <(E-Mail Removed)> wrote:

> Is there anything in c standard about the operation of file streams etc. in
> reguards to how they are supposed to act if an over flow occurs.


No. Except, of course, that merely writing to a file which is about to
"overflow" (quotes because it's not the same thing as a real numeric
overflow) may continue to write properly; may write garbage (since no
conforming program can detect the difference anyway); may return with an
error status as it would for, say, a file without write access; but may
_not_ crash the program, return nonsense, or exhibit other truly
undefined behaviour.

Richard
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      10-22-2007
MisterE wrote:

> Is there anything in c standard about the operation of file streams
> etc. in reguards to how they are supposed to act if an over flow
> occurs.


Overflow for a file?

All that Standard C guarantees is that the various I/O functions of the
Standard library, (like putc, printf etc.), will return a status value
indicating success or failure. The variable `errno` may or may not be
set to any meaningful value.

Thus though you can detect a failed operation, it's generally difficult
or not possible with Standard C to find out _why_ the operation has
failed. You might have to depend upon implementation and system
specific methods.

> I am trying to work out the correct way to handle files that
> are greater than 2^32 bytes.


On 32 bit systems, you very probably have to use non-Standard
alternatives like ftello, ftello64 etc.

You shouldn't have a problem on 64 bit systems.

> Different compilers/operating systems
> etc. all behave different for ftell.


No. ftell behaves the way the Standard defines it. However it may or may
not be sufficient under certain conditions.

> I guess the answer is its
> undefined...


It _is_ defined. You're going beyond it's specification however, so what
do you expect?

 
Reply With Quote
 
Justin Spahr-Summers
Guest
Posts: n/a
 
      10-22-2007
On Oct 22, 7:37 am, santosh <(E-Mail Removed)> wrote:
> MisterE wrote:
> > I am trying to work out the correct way to handle files that
> > are greater than 2^32 bytes.

>
> On 32 bit systems, you very probably have to use non-Standard
> alternatives like ftello, ftello64 etc.
>
> You shouldn't have a problem on 64 bit systems.


Isn't this at least part of the reason fgetpos() and fsetpos() exist?
fpos_t is allowed to be larger than a long, and even a non-integral
type, to handle possibly huge files.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      10-22-2007
Justin Spahr-Summers wrote:

> On Oct 22, 7:37 am, santosh <(E-Mail Removed)> wrote:
>> MisterE wrote:
>> > I am trying to work out the correct way to handle files that
>> > are greater than 2^32 bytes.

>>
>> On 32 bit systems, you very probably have to use non-Standard
>> alternatives like ftello, ftello64 etc.
>>
>> You shouldn't have a problem on 64 bit systems.

>
> Isn't this at least part of the reason fgetpos() and fsetpos() exist?
> fpos_t is allowed to be larger than a long, and even a non-integral
> type, to handle possibly huge files.


Yes. I should have mentioned that. When the OP said he was using ftell,
(and encountering problems), I automatically thought of ftell-like
alternatives.

As you said, fgetpos and fsetpos are Standardised and better.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard IO streams in Ruby Jatin Kumar Ruby 3 08-04-2010 01:55 AM
How to output wide strings to narrow streams with standard library? Timothy Madden C++ 1 01-19-2010 12:00 PM
Standard streams raghu Python 1 01-19-2007 12:11 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM
help with standard streams and the file descriptor Robert Schweikert C++ 1 01-06-2004 04:19 AM



Advertisments