[erlang-questions] dos new line under unix

Roger Larsson <>
Wed Dec 6 22:14:09 CET 2006


On Wednesday 06 December 2006 17:17, József Bérces wrote:
> Hi,
>
> I recently compiled one of my small erlang programs under unix and found
> that it writes dos new line characters (\r\n) instead of a single new line
> character. What determines if io:format and io:put_chars translates \n to
> \r\n?

If you opened the file as a text file or a binary file.
#man fopen

"    The  mode  string  can  also  include the letter ``b'' either as a last
       character or as a character between the characters 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 sys‐
       tems 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.)
"

=> ALWAYS open with 'b' if the file is binary.

/RogerL




More information about the erlang-questions mailing list