summaryrefslogtreecommitdiff
path: root/include/stdio.h
diff options
context:
space:
mode:
authorKurt Miller <kurt@cvs.openbsd.org>2009-11-09 00:18:29 +0000
committerKurt Miller <kurt@cvs.openbsd.org>2009-11-09 00:18:29 +0000
commitad0592d657a970d3b3d8200773732a354fad0461 (patch)
tree2d36a0624d8d3c7fac96e04ac86511d85bbcc56f /include/stdio.h
parent13102e76b8d893f7a1f4a778cc16d5e67e719a12 (diff)
Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required. Macros in <stdio.h> are updated to automatically call the underlying functions when the process is threaded to obtain the necessary locking. A private mutex is added to protect __sglue, the internal list of FILE handles, and another to protect the one-time initialization. Some routines in libc that use getc() change to use getc_unlocked() as they're either protected by their own lock or aren't thread-safe routines anyway. committing on behalf of and okay guenther@ now that we have install media space available.
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 14b65aae5ce..e23e7ad4667 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stdio.h,v 1.37 2009/10/22 01:23:16 guenther Exp $ */
+/* $OpenBSD: stdio.h,v 1.38 2009/11/09 00:18:27 kurt Exp $ */
/* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */
/*-
@@ -157,6 +157,7 @@ __END_DECLS
#define __SOFF 0x1000 /* set iff _offset is in fact correct */
#define __SMOD 0x2000 /* true => fgetln modified _p text */
#define __SALC 0x4000 /* allocate string space dynamically */
+#define __SIGN 0x8000 /* ignore this file in _fwalk */
/*
* The following three definitions are for ANSI C, which took them
@@ -322,12 +323,6 @@ char *tempnam(const char *, const char *);
#endif
__END_DECLS
-#ifndef _POSIX_THREADS
-# define flockfile(fp) /* nothing */
-# define ftrylockfile(fp) (0)
-# define funlockfile(fp) /* nothing */
-#endif
-
#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
/*
@@ -402,32 +397,37 @@ static __inline int __sputc(int _c, FILE *_p) {
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
#define __sfileno(p) ((p)->_file)
-#define feof(p) __sfeof(p)
-#define ferror(p) __sferror(p)
+extern int __isthreaded;
-#ifndef _POSIX_THREADS
-#define clearerr(p) __sclearerr(p)
-#endif
+#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) __sfileno(p)
+#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
#endif
+#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
+
+#if __BSD_VISIBLE
+/*
+ * The macro implementations of putc and putc_unlocked are not
+ * fully POSIX compliant; they do not set errno on failure
+ */
+#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
+#endif /* __BSD_VISIBLE */
+
#ifndef lint
-#ifndef _POSIX_THREADS
-#define getc(fp) __sgetc(fp)
-#endif /* _POSIX_THREADS */
+#if __POSIX_VISIBLE >= 199506
#define getc_unlocked(fp) __sgetc(fp)
/*
* The macro implementations of putc and putc_unlocked are not
* fully POSIX compliant; they do not set errno on failure
*/
#if __BSD_VISIBLE
-#ifndef _POSIX_THREADS
-#define putc(x, fp) __sputc(x, fp)
-#endif /* _POSIX_THREADS */
#define putc_unlocked(x, fp) __sputc(x, fp)
#endif /* __BSD_VISIBLE */
+#endif /* __POSIX_VISIBLE >= 199506 */
#endif /* lint */
#define getchar() getc(stdin)