Supplemental line feed(0x0A) and end of file(EOF) not logical

This forum is for general developer support questions.
Post Reply
User avatar
gdridi
Posts: 64
Joined: Sat Aug 11, 2012 10:17 am

Supplemental line feed(0x0A) and end of file(EOF) not logical

Post by gdridi »

Hello,

When I´m creating a file like (supposed to be an empty file) :
> cat >file.txt
Ctrl-\

And close immediately with Ctrl-\ (0x1C on Amiga)
The file.txt is not empty file but contains a line feed char (0x0A).

This is illogic like the test program joined (and this can lead to hard to find behavior "in programmer life also").

Code: Select all

#include <stdio.h>

// Close the input stream just after with Ctrl-\
// and it will NOT print that it is EndOfFile !
// We think this is due to a linefeed(LF) insertion before close of the DOS stream in : con-handler
int main() {
	int c = getchar();
	if ( c == EOF ) printf ("*** End Of File ***\n");
	else printf("char %d\n", c); 
}
Best regards,
DGILLES

Post scriptum : if the bug is in con-handler it can be a rapid fix to upload the separated file I.e. con-handler on a place where everyone can download it(expecting a new update of AmigaOS).
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: Supplemental line feed(0x0A) and end of file(EOF) not logical

Post by tonyw »

I'm not sure that this is a bug. It seems logical to me that if you create an ASCII (not binary) file with cat or any other ASCII-oriented program, that it ought to contain at the very least an empty line terminated by a NL.

I put it on my list of things to look into, but it's not a high priority. You can always create an empty file with the command:

"echo >emptyfile" -with no text to enter into it. That will create a completely empty file.
cheers
tony
User avatar
gdridi
Posts: 64
Joined: Sat Aug 11, 2012 10:17 am

Re: Supplemental line feed(0x0A) and end of file(EOF) not logical

Post by gdridi »

Hello,

I tried with echo and I sorry to say that’s kind of miss behavior because echo should add a newline except if the NOLiNE option is pass.

Another CMD like the touch Linux one should mimic this echo >empty_file (without text fed).

But for _test strategy_ we have the two differents commands copy and type :

Copy * to ram:toto
Or
Type * to ram:titi

And closing immediately the input stream with Ctrl-\ (0x1C) should give an empty file Toto for copy command and a file which contains newline for titi.

Other methods than copy to create empty file is : echo NOLINE >ram:tutu

Echo is ASCII aware as type, both are Line buffered so newline ; no binary as copy or cat which treated newline like other byte (it seems).

Best regards,
DGILLES - Arabic console at 18 dec 2022 on os4depot.net
Post Reply