Subj : File: writeln() and line endings
To   : Digital Man
From : Nightfox
Date : Sun Apr 27 2025 05:27 pm

 Re: File: writeln() and line endings
 By: Digital Man to Nightfox on Sat Apr 26 2025 06:26 pm

DM> On Windows, File.writeln() will append either "\n" or "\r\n" depending on
DM> how the file was opened. If it was opened in text mode (the "t" open
DM> flag), then "\r\n" is used.

DM> On Linux, the "t" open mode flag is ignored and File.writeln() will always
DM> save the text with "\n" appended. Example:

DM> var f = new File("test.blah");
DM> f.open("w");
DM> f.writeln();

DM> Creates a file with a single byte:

DM> $ hd /sbbs/ctrl/test.blah
DM> 00000000  0a                                                |.| 00000001

I was able to confirm that.

DM> If your edited file is ending up with CRLF terminated lines, that could
DM> just be the function of the console.editfile() method (if you're using
DM> that) and the underlying C++ methods that post-process the edited the
DM> file.

I am using console.editfile() to edit the file.  It seems it is indeed console.editfile() that results in the line endings being \r\n.

In my test, after creating id_rsa using console.editfile(), SSH fails to authenticate me, which seems to me is caused by the difference in line endings.

Is there a way to call console.editfile() so that it won't do any post-processing of the file?

Also, I'm a little unclear on why the underlying C++ methods would change the line endings to \r\n on Linux.  Could that be a bug, or is it intended behavior?

Nightfox

---
� Synchronet � Digital Distortion: digitaldistortionbbs.com