You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pacman flushes stdin before asking a question and doesn't have and takes any non-"y" as not, leading to user confusion if for example enter is pressed during the waiting before the question is asked, leading to surprise aborts of the process, example: msys2/MSYS2-packages#3532
This example allows you to input text, then flushes as pacman does, then reads stdin. Flushing currently doesn't have an effect.
#include<stdio.h>#include<unistd.h>#include<termios.h>intmain() {
printf("type something in the next 5 secs\n");
for (inti; i<5; i++) {
sleep(1);
printf("%d\n", i);
}
// Flush stdinintfd=fileno(stdin);
if (fd!=-1) {
printf("flushing stdin\n");
if (tcflush(fd, TCIFLUSH) ==-1) { // this doesn't seem to do anythingperror("Error flushing stdin");
return1;
}
} else {
perror("Error getting file descriptor for stdin");
return1;
}
charbuffer[100];
printf("Enter some text:\n");
fgets(buffer, sizeof(buffer), stdin);
printf("You entered: %s\n", buffer);
return0;
}
The text was updated successfully, but these errors were encountered:
This is an example extracted from pacman https://gitlab.archlinux.org/pacman/pacman/-/blob/2180e4d127af2ce0722b831a7131283604a7bdf1/src/pacman/util.c#L185
pacman flushes stdin before asking a question and doesn't have and takes any non-"y" as not, leading to user confusion if for example enter is pressed during the waiting before the question is asked, leading to surprise aborts of the process, example: msys2/MSYS2-packages#3532
This example allows you to input text, then flushes as pacman does, then reads stdin. Flushing currently doesn't have an effect.
The text was updated successfully, but these errors were encountered: