Re-add macro versions of getc(), getchar(), putc(), putchar(), feof(),
ferror(), fileno() and clearerr(), using the value of __isthreaded to decide between the fast inline single-threaded code and the more general function equivalent. This gives most of the performance benefits of the old unsafe macros while preserving thread safety.
This commit is contained in:
parent
25f740b790
commit
567d74a5ec
@ -416,6 +416,22 @@ static __inline int __sputc(int _c, FILE *_p) {
|
||||
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
|
||||
#define __sfileno(p) ((p)->_file)
|
||||
|
||||
extern int __isthreaded;
|
||||
|
||||
#define feof(p) (!__isthreaded ? __sfeof(p) : feof(p))
|
||||
#define ferror(p) (!__isthreaded ? __sferror(p) : ferror(p))
|
||||
#define clearerr(p) (!__isthreaded ? __sclearerr(p) : clearerr(p))
|
||||
|
||||
#if __POSIX_VISIBLE
|
||||
#define fileno(p) (!__isthreaded ? __sfileno(p) : fileno(p))
|
||||
#endif
|
||||
|
||||
#define getc(fp) (!__isthreaded ? __sgetc(fp) : getc(fp))
|
||||
#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : putc(x, fp))
|
||||
|
||||
#define getchar() getc(stdin)
|
||||
#define putchar(x) putc(x, stdout)
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
|
||||
|
@ -45,12 +45,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
/*
|
||||
* feof has traditionally been a macro in <stdio.h>. That is no
|
||||
* longer true because it needs to be thread-safe.
|
||||
*
|
||||
* #undef feof
|
||||
*/
|
||||
#undef feof
|
||||
|
||||
int
|
||||
feof(FILE *fp)
|
||||
{
|
||||
|
@ -45,12 +45,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
/*
|
||||
* ferror has traditionally been a macro in <stdio.h>. That is no
|
||||
* longer true because it needs to be thread-safe.
|
||||
*
|
||||
* #undef ferror
|
||||
*/
|
||||
#undef ferror
|
||||
|
||||
int
|
||||
ferror(FILE *fp)
|
||||
{
|
||||
|
@ -45,12 +45,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "un-namespace.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
/*
|
||||
* fileno has traditionally been a macro in <stdio.h>. That is
|
||||
* no longer true because it needs to be thread-safe.
|
||||
*
|
||||
* #undef fileno
|
||||
*/
|
||||
#undef fileno
|
||||
|
||||
int
|
||||
fileno(FILE *fp)
|
||||
{
|
||||
|
@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "libc_private.h"
|
||||
#include "local.h"
|
||||
|
||||
#undef getc
|
||||
|
||||
int
|
||||
getc(FILE *fp)
|
||||
{
|
||||
|
@ -46,14 +46,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "local.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
/*
|
||||
* putc has traditionally been a macro in <stdio.h>. That is no
|
||||
* longer true because POSIX requires it to be thread-safe. POSIX
|
||||
* does define putc_unlocked() which is defined as a macro and is
|
||||
* probably what you want to use instead.
|
||||
*
|
||||
* #undef putc
|
||||
*/
|
||||
#undef putc
|
||||
|
||||
int
|
||||
putc(c, fp)
|
||||
int c;
|
||||
|
@ -46,14 +46,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "local.h"
|
||||
#include "libc_private.h"
|
||||
|
||||
/*
|
||||
* putchar has traditionally been a macro in <stdio.h>. That is no
|
||||
* longer true because POSIX requires it to be thread-safe. POSIX
|
||||
* does define putchar_unlocked() which is defined as a macro and is
|
||||
* probably what you want to use instead.
|
||||
*
|
||||
* #undef putchar
|
||||
*/
|
||||
#undef putchar
|
||||
|
||||
/*
|
||||
* A subroutine version of the macro putchar
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user