Make stdin unbuffered when appropriate

This commit is contained in:
Justine Tunney 2024-05-25 07:57:13 -07:00
parent 7724664b13
commit edb03b89d8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328

View file

@ -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);
}