473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

streams - c standard

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...
Oct 22 '07 #1
4 1360
"MisterE" <Mi*****@nimga.comwrote:
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
Oct 22 '07 #2
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?

Oct 22 '07 #3
On Oct 22, 7:37 am, santosh <santosh....@gmail.comwrote:
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.

Oct 22 '07 #4
Justin Spahr-Summers wrote:
On Oct 22, 7:37 am, santosh <santosh....@gmail.comwrote:
>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.

Oct 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ronald Legere | last post by:
The new itertools stuff is pretty cool. One thing that bothers me though is that there seems to be no way to copy an iterator. How does one work around this? Is there a trick that I am missing? ...
7
by: Lasse Skyum | last post by:
I would like to implement my own i/o streams for reading from my own dataformat. Is it possible to derive one or more classes from istream,ostream or iostream to do this? When member function would...
3
by: sb | last post by:
I think streams are nice, but what do you do when you have to write to or, even worse, read from a FILE*, for example a UNIX stream? C++ streams can not be created from FILE*'s or have them...
8
by: grahamo | last post by:
Hi, I have written an app that uses streams in a very standard way. I make use of some legacy code something like this; // legacy operator<< , standard enough. ostream&...
9
by: Mantorok Redgormor | last post by:
7.19.3p7 "At program startup, three text streams are predefined and need not be opened explicitly — standard input (for reading conventional input), standard output (for writing conventional...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
2
by: Peter Rilling | last post by:
One nice thing about collections and arrays is that they implement the IEnumerator and IEnumerable interfaces which allow for more then one iterator to walk the list of items without affecting the...
2
by: Abhishek | last post by:
what are the STDUPDATE, STDERR, STDOUT and STDIN streams and how does one access these streams in C language. I am aware of the function fprintf(FILE *fp, char * format, char *s) which puts the...
3
by: Kirit Sælensminde | last post by:
>From thread http://groups.google.com/group/comp.lang.c++/browse_thread/thread/79d767efa42df516 "P.J. Plauger" <p...@dinkumware.comwrites: I'll take this at face value and I'll have to suppose...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.