diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-12 12:52:58 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-12 12:52:58 -0400 |
commit | 60c3831e53b7afa5dd372601250e7e8739329383 (patch) | |
tree | 56524ad67c32ed4bf4aa24ab06b310e5b1b5d542 /src/__main.c | |
parent | 4d4132eaebe78939ee32e2dd9139913df7665bea (diff) |
move more stuff out of nonstd/
Diffstat (limited to 'src/__main.c')
-rw-r--r-- | src/__main.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/__main.c b/src/__main.c new file mode 100644 index 00000000..14e71594 --- /dev/null +++ b/src/__main.c @@ -0,0 +1,50 @@ +#include "stdlib.h" +#include "stdio.h" +#include "locale.h" +#include "stdio/_stdio.h" + +#ifdef _POSIX_SOURCE +#define DEFAULT_LOCALE "POSIX" +#include "unistd.h" +#else +#define DEFAULT_LOCALE "C" +#include "_syscall.h" +#include "termios/NCCS.c" +#include "termios/cc_t.c" +#include "termios/tcflag_t.c" +#include "termios/struct_termios.c" +static struct termios __tios; +#define isatty(fd) (__syscall(__syscall_lookup(tcgetattr), fd, &__tios) == 0) +#endif + +void __main(int argc, char **argv) +{ + extern int main(int, char*[]); + extern char **environ; + environ = argv + argc + 1; + + stdin = __stdio.FILES + 0; + stdin->fd = 0; + /* freopen(", "r", stdin); */ + setvbuf(stdin, NULL, isatty(0) ? _IOLBF : _IOFBF, BUFSIZ); + + stdout = __stdio.FILES + 1; + stdout->fd = 1; + /* freopen(NULL, "w", stdout); */ + setvbuf(stdin, NULL, isatty(1) ? _IOLBF : _IOFBF, BUFSIZ); + + stderr = __stdio.FILES + 2; + stderr->fd = 2; + /* freopen(NULL, "w", stderr); */ + setvbuf(stderr, NULL, _IONBF, 0); + + stdin->next = stdout; + stdout->next = stderr; + + stdout->prev = stdin; + stderr->prev = stdout; + + /* setlocale(LC_ALL, DEFAULT_LOCALE); */ + + exit(main(argc, argv)); +} |