diff --git a/src/libc/ansi/stdio/stdaux.c b/src/libc/ansi/stdio/stdaux.c index dd7508b5..86267b61 100644 --- a/src/libc/ansi/stdio/stdaux.c +++ b/src/libc/ansi/stdio/stdaux.c @@ -3,9 +3,36 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include +#include -FILE __dj_stdaux = { +FILE __dj_stdaux; + +static const FILE __dj_stdaux_init = { 0, 0, 0, 0, _IORW | _IONBF, 3 }; + +struct ste_state { + FILE __dj_stdaux; +}; + +static struct ste_state *ste; + +static const struct ste_state sinit = +{ + .__dj_stdaux = __dj_stdaux_init, +}; + +static void ste_pre(void) +{ +#define _SV(x) ste->x = x + _SV(__dj_stdaux); +} +static void ste_post(void) +{ +#define _RS(x) x = ste->x + _RS(__dj_stdaux); +} +DJ64_DEFINE_SWAPPABLE_CONTEXT2(ste_state, ste, sinit, + ste_pre(), ste_post()); diff --git a/src/libc/ansi/stdio/stderr.c b/src/libc/ansi/stdio/stderr.c index a29280bb..2ac486e7 100644 --- a/src/libc/ansi/stdio/stderr.c +++ b/src/libc/ansi/stdio/stderr.c @@ -2,9 +2,36 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include +#include -FILE __dj_stderr = { +FILE __dj_stderr; + +static const FILE __dj_stderr_init = { 0, 0, 0, 0, _IOWRT | _IONBF, 2 }; + +struct ste_state { + FILE __dj_stderr; +}; + +static struct ste_state *ste; + +static const struct ste_state sinit = +{ + .__dj_stderr = __dj_stderr_init, +}; + +static void ste_pre(void) +{ +#define _SV(x) ste->x = x + _SV(__dj_stderr); +} +static void ste_post(void) +{ +#define _RS(x) x = ste->x + _RS(__dj_stderr); +} +DJ64_DEFINE_SWAPPABLE_CONTEXT2(ste_state, ste, sinit, + ste_pre(), ste_post()); diff --git a/src/libc/ansi/stdio/stdin.c b/src/libc/ansi/stdio/stdin.c index cb3551a7..3b600484 100644 --- a/src/libc/ansi/stdio/stdin.c +++ b/src/libc/ansi/stdio/stdin.c @@ -2,9 +2,36 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include +#include -FILE __dj_stdin = { +FILE __dj_stdin; + +static const FILE __dj_stdin_init = { 0, 0, 0, 0, _IOREAD | _IOLBF, 0 }; + +struct ste_state { + FILE __dj_stdin; +}; + +static struct ste_state *ste; + +static const struct ste_state sinit = +{ + .__dj_stdin = __dj_stdin_init, +}; + +static void ste_pre(void) +{ +#define _SV(x) ste->x = x + _SV(__dj_stdin); +} +static void ste_post(void) +{ +#define _RS(x) x = ste->x + _RS(__dj_stdin); +} +DJ64_DEFINE_SWAPPABLE_CONTEXT2(ste_state, ste, sinit, + ste_pre(), ste_post()); diff --git a/src/libc/ansi/stdio/stdout.c b/src/libc/ansi/stdio/stdout.c index 4d44d77b..118a6155 100644 --- a/src/libc/ansi/stdio/stdout.c +++ b/src/libc/ansi/stdio/stdout.c @@ -2,9 +2,36 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include +#include -FILE __dj_stdout = { +FILE __dj_stdout; + +static const FILE __dj_stdout_init = { 0, 0, 0, 0, _IOWRT | _IOFBF, 1 }; + +struct ste_state { + FILE __dj_stdout; +}; + +static struct ste_state *ste; + +static const struct ste_state sinit = +{ + .__dj_stdout = __dj_stdout_init, +}; + +static void ste_pre(void) +{ +#define _SV(x) ste->x = x + _SV(__dj_stdout); +} +static void ste_post(void) +{ +#define _RS(x) x = ste->x + _RS(__dj_stdout); +} +DJ64_DEFINE_SWAPPABLE_CONTEXT2(ste_state, ste, sinit, + ste_pre(), ste_post()); diff --git a/src/libc/ansi/stdio/stdprn.c b/src/libc/ansi/stdio/stdprn.c index 2ebe5e4e..1cd52638 100644 --- a/src/libc/ansi/stdio/stdprn.c +++ b/src/libc/ansi/stdio/stdprn.c @@ -3,9 +3,36 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include +#include -FILE __dj_stdprn = { +FILE __dj_stdprn; + +static const FILE __dj_stdprn_init = { 0, 0, 0, 0, _IOWRT | _IONBF, 4 }; + +struct ste_state { + FILE __dj_stdprn; +}; + +static struct ste_state *ste; + +static const struct ste_state sinit = +{ + .__dj_stdprn = __dj_stdprn_init, +}; + +static void ste_pre(void) +{ +#define _SV(x) ste->x = x + _SV(__dj_stdprn); +} +static void ste_post(void) +{ +#define _RS(x) x = ste->x + _RS(__dj_stdprn); +} +DJ64_DEFINE_SWAPPABLE_CONTEXT2(ste_state, ste, sinit, + ste_pre(), ste_post());