mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 08:42:28 +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. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/stdio/internal.h"
|
#include "libc/stdio/internal.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/sysv/consts/fileno.h"
|
#include "libc/sysv/consts/fileno.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,11 +33,14 @@ FILE *stdin;
|
||||||
static FILE __stdin;
|
static FILE __stdin;
|
||||||
|
|
||||||
__attribute__((__constructor__(60))) static textstartup void initin(void) {
|
__attribute__((__constructor__(60))) static textstartup void initin(void) {
|
||||||
|
struct stat st;
|
||||||
stdin = &__stdin;
|
stdin = &__stdin;
|
||||||
stdin->fd = STDIN_FILENO;
|
stdin->fd = STDIN_FILENO;
|
||||||
stdin->iomode = O_RDONLY;
|
stdin->iomode = O_RDONLY;
|
||||||
stdin->buf = stdin->mem;
|
stdin->buf = stdin->mem;
|
||||||
stdin->size = sizeof(stdin->mem);
|
stdin->size = sizeof(stdin->mem);
|
||||||
stdin->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
stdin->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||||
|
if (fstat(STDIN_FILENO, &st) || !S_ISREG(st.st_mode))
|
||||||
|
stdin->bufmode = _IONBF;
|
||||||
__fflush_register(stdin);
|
__fflush_register(stdin);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue