On Linux, and Unix in general, "r"
and "rb"
are the same. More specifically, a FILE
pointer obtained by fopen()
ing a file in in text mode and in binary mode behaves the same way on Unixes. On windows, and in general, on systems that use more than one character to represent "newlines", a file opened in text mode behaves as if all those characters are just one character, '\n'
.
If you want to portably read/write text files on any system, use "r"
, and "w"
in fopen()
. That will guarantee that the files are written and read properly. If you are opening a binary file, use "rb"
and "wb"
, so that an unfortunate newline-translation doesn't mess your data.
Note that a consequence of the underlying system doing the newline translation for you is that you can't determine the number of bytes you can read from a file using fseek(file, 0, SEEK_END).
Finally, see What's the difference between text and binary I/O? on comp.lang.c FAQs.