2020-06-15 07:18:57 -07:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
2024-12-16 20:51:27 -08:00
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
2020-06-15 07:18:57 -07:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 07:18:57 -07:00
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 07:18:57 -07:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2024-05-25 07:57:13 -07:00
|
|
|
#include "libc/calls/struct/stat.h"
|
2024-12-16 20:51:27 -08:00
|
|
|
#include "libc/intrin/dll.h"
|
2020-06-15 07:18:57 -07:00
|
|
|
#include "libc/stdio/internal.h"
|
2023-05-09 08:08:56 -07:00
|
|
|
#include "libc/sysv/consts/fileno.h"
|
|
|
|
#include "libc/sysv/consts/o.h"
|
2024-05-25 07:57:13 -07:00
|
|
|
#include "libc/sysv/consts/s.h"
|
2023-05-09 08:08:56 -07:00
|
|
|
#include "libc/thread/thread.h"
|
2020-06-15 07:18:57 -07:00
|
|
|
|
2024-12-16 20:51:27 -08:00
|
|
|
__static_yoink("fflush");
|
|
|
|
|
|
|
|
static char __stdin_buf[BUFSIZ];
|
|
|
|
|
2024-07-06 01:39:15 -07:00
|
|
|
static FILE __stdin = {
|
|
|
|
.fd = STDIN_FILENO,
|
2024-12-16 20:51:27 -08:00
|
|
|
.oflags = O_RDONLY,
|
2024-07-06 01:39:15 -07:00
|
|
|
.bufmode = _IOFBF,
|
2024-12-16 20:51:27 -08:00
|
|
|
.buf = __stdin_buf,
|
|
|
|
.size = sizeof(__stdin_buf),
|
2024-07-06 01:39:15 -07:00
|
|
|
.lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
|
2024-12-16 20:51:27 -08:00
|
|
|
.elem = {&__stdin.elem, &__stdin.elem},
|
2024-07-06 01:39:15 -07:00
|
|
|
};
|
|
|
|
|
2020-12-26 02:09:07 -08:00
|
|
|
/**
|
|
|
|
* Pointer to standard input stream.
|
|
|
|
*/
|
2024-07-06 01:39:15 -07:00
|
|
|
FILE *stdin = &__stdin;
|
2020-06-15 07:18:57 -07:00
|
|
|
|
2024-12-16 20:51:27 -08:00
|
|
|
__attribute__((__constructor__(60))) static textstartup void stdin_init(void) {
|
2024-05-25 07:57:13 -07:00
|
|
|
struct stat st;
|
2024-12-16 20:51:27 -08:00
|
|
|
if (fstat(STDIN_FILENO, &st) || S_ISCHR(st.st_mode))
|
2024-05-25 07:57:13 -07:00
|
|
|
stdin->bufmode = _IONBF;
|
2024-12-16 20:51:27 -08:00
|
|
|
dll_make_last(&__stdio.files, &__stdin.elem);
|
2020-06-15 07:18:57 -07:00
|
|
|
}
|