Skip to content

Commit edb03b8

Browse files
committed
Make stdin unbuffered when appropriate
1 parent 7724664 commit edb03b8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libc/stdio/stdin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
1919
#include "libc/calls/calls.h"
20+
#include "libc/calls/struct/stat.h"
2021
#include "libc/stdio/internal.h"
2122
#include "libc/stdio/stdio.h"
2223
#include "libc/sysv/consts/fileno.h"
2324
#include "libc/sysv/consts/o.h"
25+
#include "libc/sysv/consts/s.h"
2426
#include "libc/thread/thread.h"
2527

2628
/**
@@ -31,11 +33,14 @@ FILE *stdin;
3133
static FILE __stdin;
3234

3335
__attribute__((__constructor__(60))) static textstartup void initin(void) {
36+
struct stat st;
3437
stdin = &__stdin;
3538
stdin->fd = STDIN_FILENO;
3639
stdin->iomode = O_RDONLY;
3740
stdin->buf = stdin->mem;
3841
stdin->size = sizeof(stdin->mem);
3942
stdin->lock._type = PTHREAD_MUTEX_RECURSIVE;
43+
if (fstat(STDIN_FILENO, &st) || !S_ISREG(st.st_mode))
44+
stdin->bufmode = _IONBF;
4045
__fflush_register(stdin);
4146
}

0 commit comments

Comments
 (0)