mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 09:20:29 +00:00
Let signals interrupt fgets unless SA_RESTART set
See investigation in #1130. fgets internally calls readv. readv is a @restartable function that understands SA_RESTART. If SA_RESTART is set, readv already handles restarting the system call and eventually the string is transparently returned to the fgets caller. When SA_RESTART is not set, -1 EINTR should bubble up to the fgets caller. However, until this commit, fgets itself would detect EINTR and keep retrying until it read an entire line. This commit fixes this behaviour so that fgets understands SA_RESTART. I hereby assign copyright for this commit to Justine Tunney. Signed-off-by: Cadence Ember <cadence@disroot.org>
This commit is contained in:
parent
b9d6e6e348
commit
9df3689416
1 changed files with 1 additions and 5 deletions
|
@ -55,11 +55,7 @@ char *fgets_unlocked(char *s, int size, FILE *f) {
|
|||
if (t) break;
|
||||
} else {
|
||||
if ((c = fgetc_unlocked(f)) == -1) {
|
||||
if (ferror_unlocked(f) == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*p++ = c & 255;
|
||||
if (c == '\n') break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue