Jump to content
  • Advertisement
Sign in to follow this  
Sir Asksalot

files

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Yep. Doesn't matter what language you're using.

Everything on disk is in "binary", including text. The distinction between a "text file" and a "binary file" is not particularly solid, and some not all OSes handle them differently, anyway.

Usual expectations on a "text file" are:

- some character like control-D or control-Z may be expected to indicate the end of the file.
- depending on platform, either CR, LF or the CR+LF sequence is interpreted to indicate the end of a "line of text".
- (less commonly insisted upon) the last line should end with such a CR, LF or CR+LF sequence.

Opening a file in "text mode" is just used to ensure that those conventions are observed. This means that if you try to read something as a text file that was "meant" to be read as binary, then some characters may be inserted or removed (whereever there is a byte with value 10 or 13 in the file, it may be subject to "translation" from one newline encoding to another), and it might be truncated (at the first byte with value 5 (ctrl-d) or 27 (ctrl-z) in the file).

Opening a file in "binary mode" ensures that you see every byte of the file, exactly as it is recorded on disk. If you open someone else's "text file" that way, it might look double-spaced, or all run together on one line.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Asksalot here::

So there must be some kind of way the OS determines under which format the files are to be read ( like a set of bytes at the beginning of the file)??

Share this post


Link to post
Share on other sites
No, the OS does know nothing about it.
It is your responsibilty to decide wether you want to open your file in text or binary mode.

Thermo
Damn, the Mods always bring the point over much crispier :)

[Edited by - Konfusius on September 29, 2004 9:19:29 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Askalot here::

I dont mean that.I mean when you write a file.Since all files are in essence binary,there has to be some way for the OS to tell which type is which.When you write a file in text mode,it cant just be read as binary right??And vice-versa.How's that done?

Share this post


Link to post
Share on other sites
The OS doesn't care. It is your software that cares. Your software is what "reads" it in text mode, which just means there is an extra translation layer IN YOUR SOFTWARE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!