lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Nov 10, 2020 at 05:43:14PM +0100, Viacheslav Usov wrote:
> On Tue, Nov 10, 2020 at 2:27 PM Oliver Kroth <oliver.kroth@nec-i.de> wrote:
> 
> > This is neither a Lua nor a C thing.
> 
> This is a C (standard library) thing, because this is documented in
> the C language standards.
> 
> > It is actually a peculiarity of > CP/M / MSDOS / Windows, which have two modes for reading files:
> 
> Neither MS-DOS nor Windows have two file modes that would be similar
> to the C "binary" and "text" "streams" (with reference to, e.g., ISO
> C99 Standard 7.19.2). MS-DOS and Windows API expose files as bytes
> streams (or possibly sequences of fixed-size blocks of bytes), and
> they most certainly do not do any kind of translation.

Microsoft's documentation for fread says[1],

  If the given stream is opened in text mode, Windows-style newlines are
  converted into Unix-style newlines. That is, carriage return-line feed
  (CRLF) pairs are replaced by single line feed (LF) characters

and for fwrite says[2],

  If stream is opened in text mode, each line feed is replaced with a
  carriage return-line feed pair.

I assume (Classic) Mac OS performed similar translation as it used a single
carriage return for EOL.

[1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fread?view=msvc-160
[2] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fwrite?view=msvc-160