mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Make stdin unbuffered when appropriate
This commit is contained in:
parent
7724664b13
commit
edb03b89d8
1 changed files with 5 additions and 0 deletions
|
@ -17,10 +17,12 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
/**
|
||||
|
@ -31,11 +33,14 @@ FILE *stdin;
|
|||
static FILE __stdin;
|
||||
|
||||
__attribute__((__constructor__(60))) static textstartup void initin(void) {
|
||||
struct stat st;
|
||||
stdin = &__stdin;
|
||||
stdin->fd = STDIN_FILENO;
|
||||
stdin->iomode = O_RDONLY;
|
||||
stdin->buf = stdin->mem;
|
||||
stdin->size = sizeof(stdin->mem);
|
||||
stdin->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
if (fstat(STDIN_FILENO, &st) || !S_ISREG(st.st_mode))
|
||||
stdin->bufmode = _IONBF;
|
||||
__fflush_register(stdin);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue