NetBSD-Bugs archive

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

kern/56779: RAW mode on the TTY always returns EOF (-1)



>Number:         56779
>Category:       kern
>Synopsis:       RAW mode on the TTY always returns EOF  (-1)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 05 06:15:00 +0000 2022
>Originator:     mac%culver.net@localhost
>Release:        NetBSD 9.99.96
>Organization:
	
>Environment:
	
	
System: NetBSD arm64 9.99.96 NetBSD 9.99.96 (G64) #1: Tue Apr 5 04:22:19 UTC 2022 mac@arm64:/usr/obj/sys/arch/evbarm/compile/G64 evbarm
Architecture: aarch64
Machine: evbarm
>Description:
	The attached program, below, is supposed to put the terminal in RAW mode,
	and echo back characters, until the character 'c' is typed, at which point
	the program ends.

	Instead, getchar() always returns -1 independent of any characters being typed
>How-To-Repeat:
#include <stdio.h>
#include <unistd.h>   // STDIN_FILENO, isatty(), ttyname()
#include <stdlib.h>   // exit()
#include <termios.h>

int main() {
    struct termios tty_opts_backup, tty_opts_raw;

    if (!isatty(STDIN_FILENO)) {
      printf("Error: stdin is not a TTY\n");
      exit(1);
    }
    printf("stdin is %s\n", ttyname(STDIN_FILENO));

    // Back up current TTY settings
    tcgetattr(STDIN_FILENO, &tty_opts_backup);

    // Change TTY settings to raw mode
    cfmakeraw(&tty_opts_raw);
    tty_opts_raw.c_ispeed = tty_opts_backup.c_ispeed;
    tty_opts_raw.c_ospeed = tty_opts_backup.c_ospeed;
    tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);

    // Read and print characters from stdin
    int c, i = 1;
    for (c = getchar(); c != 99; c = getchar()) { // 99 = 'c'
        printf("%d. 0x%02x (0%02o)\r\n", i++, c, c);
    }
    printf("You typed 0x03 (003). Exiting.\r\n");

    // Restore previous TTY settings
    tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_backup);
}

>Fix:
	

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index