ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Originally posted by Hko Note: Opening a file in "binary" mode or in in "text mode" does not make any difference in UNIX/Linux. It has effect only on DOS/Windows (and MacOS?)
Yes. The main reason why we need to use text/binary modes is that windows/dos treats a line break as 2 characters. ( Can't rem which 2 though, never bother to remember). When a file is in text mode, the windows io calls will convert instances of the \n character into it's 2 components and vice versa. It does not do this translation if the file is in binary mode. On *nix, a line break is just a single character; so there is no need for such translation at all. There is no distinction of a text file and a binary file on a *nix. (other than the kinds of ..err.. bytes you can find in them)
The mode string can also include the letter ``b'' either
as a last character or as a character between the charac-
ters in any of the two-character strings described above.
This is strictly for compatibility with ANSI X3.159-1989
(``ANSI C'') and has no effect; the ``b'' is ignored on
all POSIX conforming systems, including Linux. (Other
systems may treat text files and binary files differently,
and adding the ``b'' may be a good idea if you do I/O to a
binary file and expect that your program may be ported to
non-Unix environments.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.