lua-users home
lua-l archive

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


On 24/03/2022 13:50, Thijs Schreijer wrote:
> My expectations were that it would in all cases treat CRLF and LF
> The same way, similar to the way the Lua source code can be read.

Just open the file in 'text mode' (plain "r" or "w", as opposed to "rb"
or "wb") and everything on the code side just sees plain LF ('\n'), so
you only need to worry about detecting that.

In the file, on Windows, the CR ('\r') is added in silently when
writing, and removed again when reading (in text mode)

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fwrite?view=msvc-170
> If stream is opened in text mode, each line feed is replaced with a carriage return-line feed pair. The replacement has no effect on the return value.


https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fread?view=msvc-170
> 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