summaryrefslogtreecommitdiffstats
path: root/include/stdio.h
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-03-17 01:43:08 +0000
committertjr <tjr@FreeBSD.org>2004-03-17 01:43:08 +0000
commitb4d98c68558acbe9782e24963999f922d52ccf28 (patch)
treea146c0d7f2efde65782926d4c69016d3b4715398 /include/stdio.h
parent131892ca17e9e6a23bd98f9bef05d035b36d2790 (diff)
downloadFreeBSD-src-b4d98c68558acbe9782e24963999f922d52ccf28.zip
FreeBSD-src-b4d98c68558acbe9782e24963999f922d52ccf28.tar.gz
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.
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 58f4995..90428b9 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -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
OpenPOWER on IntegriCloud