getchar() does not return EOF immediately on AmigaOS 4.1

A forum for general AmigaOS 4.x support questions that are not platform-specific
Post Reply
FlynnTheAvatar
Posts: 10
Joined: Thu Aug 11, 2022 1:41 pm

getchar() does not return EOF immediately on AmigaOS 4.1

Post by FlynnTheAvatar »

Hi everyone,

I’ve run into a strange stdin/EOF behaviour on AmigaOS 4.1 and wanted to check whether this is expected or a known issue.

I’m using the following minimal test program:

Code: Select all

/* compile with gcc test.c -o test
   run and press CTRL-D (linux) or CTRL-\ (AmigaOS)
   program should end without printing anything */

#include <stdio.h>

int main()
{
    int input;

    while ((input = getchar()) != EOF) {
        printf("got char %d\n", input);
    }

    return 0;
}
On Linux and also on AmigaOS 3.2.3, pressing EOF immediately ends the program with no output — exactly as expected.

On AmigaOS 4.1, however, the program always prints:

Code: Select all


got char 10
Only after that does it terminate.

This happens regardless of which C library I compile against: newlib, clib2, clib4, or vc. So it doesn’t seem to be tied to a specific runtime.

It looks like the console is delivering a newline character before reporting EOF. I’m not sure whether this is intended behaviour of the AmigaOS 4.1 shell, something in the console device, or a library quirk.

Environment:
- AmigaOS 4.1 Final Edition
- GCC toolchain, VBCC
- Tested with newlib, clib2, clib4, vc
- Standard shell, CTRL-\ for EOF

Has anyone seen this before or knows whether AmigaOS 4.1 handles EOF differently?
Any hints about the underlying stdin behaviour or console mode would be appreciated.
FlynnTheAvatar
Posts: 10
Joined: Thu Aug 11, 2022 1:41 pm

Re: getchar() does not return EOF immediately on AmigaOS 4.1

Post by FlynnTheAvatar »

Hi all,

The extra LF clearly comes from the AmigaOS 4.1 CON: handler. When sending the EOF signal, CON: always emits a final newline before actually reporting EOF. It’s independent of the C runtime — newlib, clib2, clib4, and vc all just pass through what the console device delivers.

With Vinced, the behaviour disappears: EOF is delivered immediately with no extra character.

If anyone has details on whether this newline-before-EOF behaviour is intentional in the OS4 console, I’d be interested.
thomasrapp
Posts: 321
Joined: Sun Jun 19, 2011 12:22 am

Re: getchar() does not return EOF immediately on AmigaOS 4.1

Post by thomasrapp »

Seems like this only happens if the window has the /TABBED tag. It also prevents the window from closing temporarily if it has the /AUTO tag. Without /TABBED it appears to work correctly.
FlynnTheAvatar
Posts: 10
Joined: Thu Aug 11, 2022 1:41 pm

Re: getchar() does not return EOF immediately on AmigaOS 4.1

Post by FlynnTheAvatar »

@thomasrapp

Thanks for checking. This also happens to me without /TABBED.

That is how I start my CON:

Code: Select all

NEWSHELL FROM=S:Shell-Startup WINDOW=CON:1055/31/673/484/AmigaShell/SHELL/CLOSE/ALT1055/31/673/969
S:Shell-Startup:

Code: Select all

; $VER: Shell-Startup 52.1 (15.12.2006)

Alias Clear "Echo NOLINE *"*E[0;0H*E[J*" "
Alias Cls Clear
Alias XCopy "Copy CLONE "
Alias Italic "Echo NOLINE *"*E[3m*""
Alias Bold "Echo NOLINE *"*E[1m*""
Alias Normal "Echo NOLINE *"*E[0m*""
Alias Underline "Echo NOLINE *"*E[4m*""
Alias vim "vi"
Alias less "more"
Alias Annotate "Work:Annotate/ann_RA"


Echo "*E[0;0H*E[J"
Version
Echo ""
Date
Echo ""
Avail SHOW=MEGA
ECHO ""

Prompt "*E[34m%N. *E[32m*E[1m>*E[0m *E[33m%S *E[32m*E[1m>*E[0m "
Post Reply