By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

low level eof()

P: n/a
Hi, anyone knows eof() function substitute for linux using open, close
and read functions? I am tired of searching in google, sorry

Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* Ulterior:
Hi, anyone knows eof() function substitute for linux using open, close
and read functions? I am tired of searching in google, sorry
Ask in a linux newsgroup.

This is a C++ newsgroup.
Cheers, & hth.,

- Alf
Jun 27 '08 #2

P: n/a
Ulterior <le***************@gmail.comwrites:
Hi, anyone knows eof() function substitute for linux using open, close
and read functions? I am tired of searching in google, sorry
Yes, and you could even be tired to death if you went on, since there
is no such function.

EOF is not a state, it's a condition that is encoutered when you _try_
to read past the 'end of the file'.

EOF is when read(2) returns 0.

--
__Pascal Bourguignon__
Jun 27 '08 #3

P: n/a
On Apr 14, 9:48 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
Ulterior <leonardas.surv...@gmail.comwrites:
Hi, anyone knows eof() function substitute for linux using open, close
and read functions? I am tired of searching in google, sorry
Yes, and you could even be tired to death if you went on,
since there is no such function.
EOF is not a state, it's a condition that is encoutered when
you _try_ to read past the 'end of the file'.
Just a nit, but EOF is a macro, defined to expand to an integral
constant expression of type int and a negative value. Anytime
you see a function which reads (narrow) characters, but returns
an int, you can pretty much assume that it returns a value in
the range 0...UCHAR_MAX (with the character), or EOF. (Note
that this means that the results of assigning it to a char, even
after testing for EOF, is implementation defined---and may raise
an implementation defined signal! In practice, any
implementation which didn't support this would break so much
code it wouldn't be used.)

If you want to be "in", in C++, you'll write
"std::char_traits< char >::eof()" in its place. (I'm an old
fogey, who's not in, so I still write EOF. Except in a
template.)
EOF is when read(2) returns 0.
Some filebuf implementations will also return EOF when read
returns -1:-). (This was, of course, about all they could do in
the classical iostream, before exceptions.)

The Unix file system, as such, doesn't recognize end of file as
a particular condition. A function like read will read as many
bytes as are available, up to a maximum that you specify, from
the current position in the file. The exact conditions
defining when it might return with less bytes than requested
depend on the file type, and in the case of "streams", how the
stream has been configured. For regular files, returning with
less than you requested means that you have reached the current
end of the file. The current end; if someone appends data to
the file, a later read will return it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.