From 2c6147ab6c567babf07b85820e99f541e423614a Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 4 Mar 2020 03:14:54 -0500 Subject: fix compilation when c=199409 --- src/stdio/_stdio.h | 13 +++++++++---- src/stdio/flockfile.c | 9 +++++++++ src/stdio/funlockfile.c | 9 +++++++++ src/stdio/getc_unlocked.c | 23 +++++++++++++++++++++++ src/stdio/getchar_unlocked.c | 10 ++++++++++ src/stdio/putc_unlocked.c | 10 ++++++++++ src/stdio/putchar_unlocked.c | 10 ++++++++++ src/wchar/fgetwc.c | 6 ++++++ 8 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 src/stdio/flockfile.c create mode 100644 src/stdio/funlockfile.c create mode 100644 src/stdio/getc_unlocked.c create mode 100644 src/stdio/getchar_unlocked.c create mode 100644 src/stdio/putc_unlocked.c create mode 100644 src/stdio/putchar_unlocked.c diff --git a/src/stdio/_stdio.h b/src/stdio/_stdio.h index 3335fa7e..84ad60ca 100644 --- a/src/stdio/_stdio.h +++ b/src/stdio/_stdio.h @@ -3,9 +3,14 @@ #include #include -#include "../sys/types/pid_t.c" #include "nonstd/internal.h" +#ifdef _POSIX_C_SOURCE +#include +#else +#include "../sys/types/pid_t.c" +#endif + struct __FILE { fpos_t pos; char *buf; @@ -49,9 +54,9 @@ struct io_options { int __printf(struct io_options * restrict, const char * restrict, va_list); int __scanf(struct io_options * restrict, const char * restrict, va_list); -#ifndef _POSIX_C_SOURCE -#define flockfile(...) -#define funlockfile(...) +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199506L +#define flockfile(_file) (void)(_file) +#define funlockfile(_file) (void)(_file) #endif #endif diff --git a/src/stdio/flockfile.c b/src/stdio/flockfile.c new file mode 100644 index 00000000..d8d5776b --- /dev/null +++ b/src/stdio/flockfile.c @@ -0,0 +1,9 @@ +#include + +void flockfile(FILE * file) +{ +} + +/* +POSIX(199506) +*/ diff --git a/src/stdio/funlockfile.c b/src/stdio/funlockfile.c new file mode 100644 index 00000000..b85f4842 --- /dev/null +++ b/src/stdio/funlockfile.c @@ -0,0 +1,9 @@ +#include + +void funlockfile(FILE * file) +{ +} + +/* +POSIX(199506) +*/ diff --git a/src/stdio/getc_unlocked.c b/src/stdio/getc_unlocked.c new file mode 100644 index 00000000..8abae5de --- /dev/null +++ b/src/stdio/getc_unlocked.c @@ -0,0 +1,23 @@ +#include +#include "_stdio.h" +#include "unistd.h" + +int getc_unlocked(FILE * stream) +{ + char c = 0; + + if (!stream) { + return EOF; + } + + if (read(stream->fd, &c, sizeof(c)) != 1) { + stream->err = 1; + return EOF; + } + + return c; +} + +/* +POSIX(199506) +*/ diff --git a/src/stdio/getchar_unlocked.c b/src/stdio/getchar_unlocked.c new file mode 100644 index 00000000..adeeccbd --- /dev/null +++ b/src/stdio/getchar_unlocked.c @@ -0,0 +1,10 @@ +#include + +int getchar_unlocked(void) +{ + return getc_unlocked(stdin); +} + +/* +POSIX(199506) +*/ diff --git a/src/stdio/putc_unlocked.c b/src/stdio/putc_unlocked.c new file mode 100644 index 00000000..77068408 --- /dev/null +++ b/src/stdio/putc_unlocked.c @@ -0,0 +1,10 @@ +#include + +int putc_unlocked(int c, FILE * stream) +{ + return 0; +} + +/* +POSIX(199506) +*/ diff --git a/src/stdio/putchar_unlocked.c b/src/stdio/putchar_unlocked.c new file mode 100644 index 00000000..aecfe4a1 --- /dev/null +++ b/src/stdio/putchar_unlocked.c @@ -0,0 +1,10 @@ +#include + +int putchar_unlocked(int c) +{ + return putc_unlocked(c, stdout); +} + +/* +POSIX(199506) +*/ diff --git a/src/wchar/fgetwc.c b/src/wchar/fgetwc.c index 1ae00f59..2c4d0d24 100644 --- a/src/wchar/fgetwc.c +++ b/src/wchar/fgetwc.c @@ -3,6 +3,12 @@ #include "../stdio/_stdio.h" #include "limits.h" +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199506L +#include "../unistd/read.c" +static int getc_unlocked(FILE *); +#include "../stdio/getc_unlocked.c" +#endif + wint_t fgetwc(FILE * stream) { if (fwide(stream, 1) <= 0) { -- cgit v1.2.1