1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-29 03:19:54 +00:00

Merge pull request #918 from paulsnar/paulsnar/shell-read-intr

Handle interrupts during `read` properly in mainclient
This commit is contained in:
Calvin Rose 2022-02-04 22:39:22 -06:00 committed by GitHub
commit 66e0b53cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,7 @@
#endif #endif
#include <janet.h> #include <janet.h>
#include <errno.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -75,6 +76,9 @@ static void simpleline(JanetBuffer *buffer) {
int c; int c;
for (;;) { for (;;) {
c = fgetc(in); c = fgetc(in);
if (c < 0 && !feof(in) && errno == EINTR) {
continue;
}
if (feof(in) || c < 0) { if (feof(in) || c < 0) {
break; break;
} }
@ -112,7 +116,6 @@ https://github.com/antirez/linenoise/blob/master/linenoise.c
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -742,7 +745,11 @@ static int line() {
char c; char c;
char seq[3]; char seq[3];
if (read(STDIN_FILENO, &c, 1) <= 0) return -1; int rc;
do {
rc = read(STDIN_FILENO, &c, 1);
} while (rc < 0 && errno == EINTR);
if (rc <= 0) return -1;
switch (c) { switch (c) {
default: default: