From 79899f6b3cade5b0ad39b70d30ccf15f182ba045 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 16 May 2013 14:04:39 +0000 Subject: [PATCH] stdio: inline getchar/putchar Some apps like lvm2 modifies stdin. This breaks getchar since it is a macro that uses __stdin. (cherry picked from commit aabeb90f74aa2736fb993cd5840a894eff3b958f) Conflicts: include/stdio.h libc/sysdeps/linux/common/bits/uClibc_stdio.h --- include/stdio.h | 17 +++++++---------- libc/stdio/getchar.c | 2 -- libc/stdio/putchar.c | 3 --- libc/sysdeps/linux/common/bits/uClibc_stdio.h | 6 ------ 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 289b861..4d6092a 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -906,19 +906,16 @@ extern void funlockfile (FILE *__stream) __THROW; #define fputc_unlocked(_ch, _fp) __FPUTC_UNLOCKED(_ch, _fp) #endif -#ifndef __STDIO_GETC_MACRO -#define __stdin stdin -#endif -#define getchar() __GETC(__stdin) +#ifdef __USE_EXTERN_INLINES -#ifndef __STDIO_PUTC_MACRO -#define __stdout stdout -#endif -#define putchar(_ch) __PUTC((_ch), __stdout) +__extern_inline int getchar(void) { return __GETC(stdin); } +__extern_inline int putchar(int c) { return __PUTC(c, stdout); } #if defined __USE_POSIX || defined __USE_MISC -#define getchar_unlocked() __GETC_UNLOCKED(__stdin) -#define putchar_unlocked(_ch) __PUTC_UNLOCKED((_ch), __stdout) +__extern_inline int getchar_unlocked(void) { return __GETC_UNLOCKED(stdin); } +__extern_inline int putchar_unlocked(int c) { return __PUTC_UNLOCKED(c, stdout); } +#endif + #endif /* Clear the error and EOF indicators for STREAM. */ diff --git a/libc/stdio/getchar.c b/libc/stdio/getchar.c index b6c650c..f8c487b 100644 --- a/libc/stdio/getchar.c +++ b/libc/stdio/getchar.c @@ -8,11 +8,9 @@ #include "_stdio.h" -#undef getchar #ifdef __DO_UNLOCKED /* the only use of the hidden getchar_unlocked is in gets.c */ -#undef getchar_unlocked int getchar_unlocked(void) { register FILE *stream = stdin; diff --git a/libc/stdio/putchar.c b/libc/stdio/putchar.c index 583e90f..804b09d 100644 --- a/libc/stdio/putchar.c +++ b/libc/stdio/putchar.c @@ -7,11 +7,8 @@ #include "_stdio.h" - -#undef putchar #ifdef __DO_UNLOCKED -#undef putchar_unlocked int putchar_unlocked(int c) { register FILE *stream = stdout; diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h index a8cf4eb..2ec8ad4 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h +++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h @@ -411,8 +411,6 @@ libc_hidden_proto(__fputc_unlocked) #ifdef __STDIO_GETC_MACRO -extern FILE *__stdin; /* For getchar() macro. */ - # undef __GETC_UNLOCKED_MACRO # define __GETC_UNLOCKED_MACRO(__stream) \ ( ((__stream)->__bufpos < (__stream)->__bufgetc_u) \ @@ -463,15 +461,11 @@ extern FILE *__stdin; /* For getchar() macro. */ # endif # endif -#else - #endif /* __STDIO_GETC_MACRO */ #ifdef __STDIO_PUTC_MACRO -extern FILE *__stdout; /* For putchar() macro. */ - # undef __PUTC_UNLOCKED_MACRO # define __PUTC_UNLOCKED_MACRO(__c, __stream) \ ( ((__stream)->__bufpos < (__stream)->__bufputc_u) \ -- 1.8.2.3