From da2013ac86e736cdbf57637d9c0e48f1215dca10 Mon Sep 17 00:00:00 2001 From: jtc Date: Mon, 19 Jan 1998 07:38:41 +0000 Subject: [PATCH] Use FLOCKFILE() and FUNLOCKFILE() macros from reentrant.h so that stdio can be made thread-safe. --- lib/libc/stdio/clrerr.c | 8 ++++++-- lib/libc/stdio/fclose.c | 8 ++++++-- lib/libc/stdio/fflush.c | 15 +++++++++++---- lib/libc/stdio/fgetc.c | 12 +++++++++--- lib/libc/stdio/fgetln.c | 11 +++++++++-- lib/libc/stdio/fgets.c | 7 +++++-- lib/libc/stdio/fpurge.c | 8 ++++++-- lib/libc/stdio/fputc.c | 12 +++++++++--- lib/libc/stdio/fputs.c | 11 ++++++++--- lib/libc/stdio/fread.c | 8 ++++++-- lib/libc/stdio/fseek.c | 16 +++++++++++++--- lib/libc/stdio/ftell.c | 13 ++++++++++--- lib/libc/stdio/fwrite.c | 13 ++++++++----- lib/libc/stdio/getc.c | 21 ++++++++++++++++++--- lib/libc/stdio/getchar.c | 20 +++++++++++++++++--- lib/libc/stdio/putc.c | 21 ++++++++++++++++++--- lib/libc/stdio/putchar.c | 21 +++++++++++++++++---- 17 files changed, 176 insertions(+), 49 deletions(-) diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index add34da8a7af..14d8e93a75b5 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -1,4 +1,4 @@ -/* $NetBSD: clrerr.c,v 1.5 1997/07/13 20:14:49 christos Exp $ */ +/* $NetBSD: clrerr.c,v 1.6 1998/01/19 07:38:41 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,15 +41,19 @@ #if 0 static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; #endif -__RCSID("$NetBSD: clrerr.c,v 1.5 1997/07/13 20:14:49 christos Exp $"); +__RCSID("$NetBSD: clrerr.c,v 1.6 1998/01/19 07:38:41 jtc Exp $"); #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" + #undef clearerr void clearerr(fp) FILE *fp; { + FLOCKFILE(fp); __sclearerr(fp); + FUNLOCKFILE(fp); } diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 9680b5a8d991..b9444e850a55 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -1,4 +1,4 @@ -/* $NetBSD: fclose.c,v 1.6 1997/07/13 20:14:49 christos Exp $ */ +/* $NetBSD: fclose.c,v 1.7 1998/01/19 07:38:42 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; #endif -__RCSID("$NetBSD: fclose.c,v 1.6 1997/07/13 20:14:49 christos Exp $"); +__RCSID("$NetBSD: fclose.c,v 1.7 1998/01/19 07:38:42 jtc Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include #include #include "local.h" +#include "reentrant.h" int fclose(fp) @@ -55,8 +56,10 @@ fclose(fp) { register int r; + FLOCKFILE(fp); if (fp->_flags == 0) { /* not open! */ errno = EBADF; + FUNLOCKFILE(fp); return (EOF); } r = fp->_flags & __SWR ? __sflush(fp) : 0; @@ -70,5 +73,6 @@ fclose(fp) FREELB(fp); fp->_flags = 0; /* Release this FILE for reuse. */ fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ + FUNLOCKFILE(fp); return (r); } diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index f821fad07f75..e315a14fd06e 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.8 1997/07/13 20:14:52 christos Exp $ */ +/* $NetBSD: fflush.c,v 1.9 1998/01/19 07:38:42 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,27 +41,34 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.8 1997/07/13 20:14:52 christos Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.9 1998/01/19 07:38:42 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include #include "local.h" +#include "reentrant.h" /* Flush a single file, or (if fp is NULL) all files. */ int fflush(fp) register FILE *fp; { + int r; if (fp == NULL) return (_fwalk(__sflush)); + + FLOCKFILE(fp); if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; - return (EOF); + r = EOF; + } else { + r = __sflush(fp); } - return (__sflush(fp)); + FUNLOCKFILE(fp); + return r; } int diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 3a74329f6ac9..1d520610db0f 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetc.c,v 1.6 1997/07/13 20:14:53 christos Exp $ */ +/* $NetBSD: fgetc.c,v 1.7 1998/01/19 07:38:43 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,15 +41,21 @@ #if 0 static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fgetc.c,v 1.6 1997/07/13 20:14:53 christos Exp $"); +__RCSID("$NetBSD: fgetc.c,v 1.7 1998/01/19 07:38:43 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" int fgetc(fp) FILE *fp; { - return (__sgetc(fp)); + int r; + + FLOCKFILE(fp); + r = __sgetc(fp); + FUNLOCKFILE(fp); + return r; } diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c index 2503b56d61f0..021ec40c72d7 100644 --- a/lib/libc/stdio/fgetln.c +++ b/lib/libc/stdio/fgetln.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetln.c,v 1.3 1997/07/13 20:14:54 christos Exp $ */ +/* $NetBSD: fgetln.c,v 1.4 1998/01/19 07:38:44 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fgetln.c,v 1.3 1997/07/13 20:14:54 christos Exp $"); +__RCSID("$NetBSD: fgetln.c,v 1.4 1998/01/19 07:38:44 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,6 +49,7 @@ __RCSID("$NetBSD: fgetln.c,v 1.3 1997/07/13 20:14:54 christos Exp $"); #include #include #include "local.h" +#include "reentrant.h" int __slbexpand __P((FILE *, size_t)); @@ -94,9 +95,12 @@ fgetln(fp, lenp) register size_t len; size_t off; + FLOCKFILE(fp); + /* make sure there is input */ if (fp->_r <= 0 && __srefill(fp)) { *lenp = 0; + FUNLOCKFILE(fp); return (NULL); } @@ -115,6 +119,7 @@ fgetln(fp, lenp) fp->_flags |= __SMOD; fp->_r -= len; fp->_p = p; + FUNLOCKFILE(fp); return (ret); } @@ -162,9 +167,11 @@ fgetln(fp, lenp) #ifdef notdef fp->_lb._base[len] = 0; #endif + FUNLOCKFILE(fp); return ((char *)fp->_lb._base); error: *lenp = 0; /* ??? */ + FUNLOCKFILE(fp); return (NULL); /* ??? */ } diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index d9c999b968dd..09f5514865a6 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgets.c,v 1.6 1997/07/13 20:14:55 christos Exp $ */ +/* $NetBSD: fgets.c,v 1.7 1998/01/19 07:38:44 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; #else -__RCSID("$NetBSD: fgets.c,v 1.6 1997/07/13 20:14:55 christos Exp $"); +__RCSID("$NetBSD: fgets.c,v 1.7 1998/01/19 07:38:44 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include #include "local.h" +#include "reentrant.h" /* * Read at most n-1 characters from the given file. @@ -67,6 +68,7 @@ fgets(buf, n, fp) if (n <= 0) /* sanity check */ return (NULL); + FLOCKFILE(fp); s = buf; n--; /* leave space for NUL */ while (n != 0) { @@ -108,5 +110,6 @@ fgets(buf, n, fp) n -= len; } *s = 0; + FUNLOCKFILE(fp); return (buf); } diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index e0331331d03f..da47677a3c30 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -1,4 +1,4 @@ -/* $NetBSD: fpurge.c,v 1.5 1997/07/13 20:15:01 christos Exp $ */ +/* $NetBSD: fpurge.c,v 1.6 1998/01/19 07:38:45 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fpurge.c,v 1.5 1997/07/13 20:15:01 christos Exp $"); +__RCSID("$NetBSD: fpurge.c,v 1.6 1998/01/19 07:38:45 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,6 +49,7 @@ __RCSID("$NetBSD: fpurge.c,v 1.5 1997/07/13 20:15:01 christos Exp $"); #include #include #include "local.h" +#include "reentrant.h" /* * fpurge: like fflush, but without writing anything: leave the @@ -58,8 +59,10 @@ int fpurge(fp) register FILE *fp; { + FLOCKFILE(fp); if (!fp->_flags) { errno = EBADF; + FUNLOCKFILE(fp); return(EOF); } @@ -68,5 +71,6 @@ fpurge(fp) fp->_p = fp->_bf._base; fp->_r = 0; fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + FUNLOCKFILE(fp); return (0); } diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index 3473b590d65c..2471baca6698 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputc.c,v 1.6 1997/07/13 20:15:02 christos Exp $ */ +/* $NetBSD: fputc.c,v 1.7 1998/01/19 07:38:46 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,16 +41,22 @@ #if 0 static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fputc.c,v 1.6 1997/07/13 20:15:02 christos Exp $"); +__RCSID("$NetBSD: fputc.c,v 1.7 1998/01/19 07:38:46 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" int fputc(c, fp) int c; register FILE *fp; { - return (putc(c, fp)); + int r; + + FLOCKFILE(fp); + r = __sputc(c, fp); + FUNLOCKFILE(fp); + return r; } diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 5adf95b5a542..1ad5d33ac9c0 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputs.c,v 1.6 1997/07/13 20:15:02 christos Exp $ */ +/* $NetBSD: fputs.c,v 1.7 1998/01/19 07:38:46 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fputs.c,v 1.6 1997/07/13 20:15:02 christos Exp $"); +__RCSID("$NetBSD: fputs.c,v 1.7 1998/01/19 07:38:46 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include #include "fvwrite.h" +#include "reentrant.h" /* * Write the given string to the given file. @@ -59,10 +60,14 @@ fputs(s, fp) { struct __suio uio; struct __siov iov; + int r; iov.iov_base = (void *)s; iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; - return (__sfvwrite(fp, &uio)); + FLOCKFILE(fp); + r = __sfvwrite(fp, &uio); + FUNLOCKFILE(fp); + return r; } diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index 1b1195dc648d..4101cb07d863 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.7 1997/07/13 20:15:03 christos Exp $ */ +/* $NetBSD: fread.c,v 1.8 1998/01/19 07:38:47 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.7 1997/07/13 20:15:03 christos Exp $"); +__RCSID("$NetBSD: fread.c,v 1.8 1998/01/19 07:38:47 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include #include "local.h" +#include "reentrant.h" size_t fread(buf, size, count, fp) @@ -67,6 +68,7 @@ fread(buf, size, count, fp) */ if ((resid = count * size) == 0) return (0); + FLOCKFILE(fp); if (fp->_r < 0) fp->_r = 0; total = resid; @@ -79,11 +81,13 @@ fread(buf, size, count, fp) resid -= r; if (__srefill(fp)) { /* no more input: return partial result */ + FUNLOCKFILE(fp); return ((total - resid) / size); } } (void)memcpy((void *)p, (void *)fp->_p, resid); fp->_r -= resid; fp->_p += resid; + FUNLOCKFILE(fp); return (count); } diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 96d8e3836f49..91f916982239 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -1,4 +1,4 @@ -/* $NetBSD: fseek.c,v 1.11 1997/12/19 14:08:41 kleink Exp $ */ +/* $NetBSD: fseek.c,v 1.12 1998/01/19 07:38:48 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: fseek.c,v 1.11 1997/12/19 14:08:41 kleink Exp $"); +__RCSID("$NetBSD: fseek.c,v 1.12 1998/01/19 07:38:48 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,6 +52,7 @@ __RCSID("$NetBSD: fseek.c,v 1.11 1997/12/19 14:08:41 kleink Exp $"); #include #include #include "local.h" +#include "reentrant.h" #define POS_ERR (-(fpos_t)1) @@ -75,6 +76,8 @@ fseek(fp, offset, whence) if (!__sdidinit) __sinit(); + FLOCKFILE(fp); + /* * Have to be able to seek. */ @@ -100,8 +103,10 @@ fseek(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1L) + if (curoff == -1L) { + FUNLOCKFILE(fp); return (-1); + } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -123,6 +128,7 @@ fseek(fp, offset, whence) default: errno = EINVAL; + FUNLOCKFILE(fp); return (-1); } @@ -206,6 +212,7 @@ fseek(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; + FUNLOCKFILE(fp); return (0); } @@ -232,6 +239,7 @@ fseek(fp, offset, whence) fp->_p += n; fp->_r -= n; } + FUNLOCKFILE(fp); return (0); /* @@ -241,6 +249,7 @@ fseek(fp, offset, whence) dumb: if (__sflush(fp) || (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { + FUNLOCKFILE(fp); return (-1); } /* success: clear EOF indicator and discard ungetc() data */ @@ -250,5 +259,6 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; + FUNLOCKFILE(fp); return (0); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 0afcd2c2e775..01ef78e55da4 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftell.c,v 1.7 1997/07/13 20:15:07 christos Exp $ */ +/* $NetBSD: ftell.c,v 1.8 1998/01/19 07:38:48 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)ftell.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ftell.c,v 1.7 1997/07/13 20:15:07 christos Exp $"); +__RCSID("$NetBSD: ftell.c,v 1.8 1998/01/19 07:38:48 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include #include "local.h" +#include "reentrant.h" /* * ftell: return current offset. @@ -58,7 +59,10 @@ ftell(fp) { register fpos_t pos; + FLOCKFILE(fp); + if (fp->_seek == NULL) { + FUNLOCKFILE(fp); errno = ESPIPE; /* historic practice */ return (-1L); } @@ -72,8 +76,10 @@ ftell(fp) pos = fp->_offset; else { pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1L) + if (pos == -1L) { + FUNLOCKFILE(fp); return (pos); + } } if (fp->_flags & __SRD) { /* @@ -92,5 +98,6 @@ ftell(fp) */ pos += fp->_p - fp->_bf._base; } + FUNLOCKFILE(fp); return (pos); } diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 1831f35568bc..405627cd2549 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwrite.c,v 1.6 1997/07/13 20:15:10 christos Exp $ */ +/* $NetBSD: fwrite.c,v 1.7 1998/01/19 07:38:49 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,14 @@ #if 0 static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fwrite.c,v 1.6 1997/07/13 20:15:10 christos Exp $"); +__RCSID("$NetBSD: fwrite.c,v 1.7 1998/01/19 07:38:49 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include "local.h" #include "fvwrite.h" +#include "reentrant.h" /* * Write `count' objects (each size `size') from memory to the given file. @@ -73,7 +74,9 @@ fwrite(buf, size, count, fp) * skip the divide if this happens, since divides are * generally slow and since this occurs whenever size==0. */ - if (__sfvwrite(fp, &uio) == 0) - return (count); - return ((n - uio.uio_resid) / size); + FLOCKFILE(fp); + if (__sfvwrite(fp, &uio) != 0) + count = ((n - uio.uio_resid) / size); + FUNLOCKFILE(fp); + return (count); } diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index 98fcda679c63..de2081896235 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -1,4 +1,4 @@ -/* $NetBSD: getc.c,v 1.6 1997/07/13 20:15:10 christos Exp $ */ +/* $NetBSD: getc.c,v 1.7 1998/01/19 07:38:50 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,20 +41,35 @@ #if 0 static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getc.c,v 1.6 1997/07/13 20:15:10 christos Exp $"); +__RCSID("$NetBSD: getc.c,v 1.7 1998/01/19 07:38:50 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" /* * A subroutine version of the macro getc. */ #undef getc +#undef getc_unlocked int getc(fp) - register FILE *fp; + FILE *fp; { + int r; + + FLOCKFILE(fp); + r = __sgetc(fp); + FUNLOCKFILE(fp); + return r; +} + +int +getc_unlocked(fp) + FILE *fp; +{ + return (__sgetc(fp)); } diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index a1b280e54c45..5700779e00f1 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -1,4 +1,4 @@ -/* $NetBSD: getchar.c,v 1.6 1997/07/13 20:15:11 christos Exp $ */ +/* $NetBSD: getchar.c,v 1.7 1998/01/19 07:38:51 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getchar.c,v 1.6 1997/07/13 20:15:11 christos Exp $"); +__RCSID("$NetBSD: getchar.c,v 1.7 1998/01/19 07:38:51 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,11 +49,25 @@ __RCSID("$NetBSD: getchar.c,v 1.6 1997/07/13 20:15:11 christos Exp $"); * A subroutine version of the macro getchar. */ #include +#include "reentrant.h" #undef getchar +#undef getchar_unlocked int getchar() { - return (getc(stdin)); + FILE *fp = stdin; + int r; + + FLOCKFILE(fp); + r = __sgetc(fp); + FUNLOCKFILE(fp); + return r; +} + +int +getchar_unlocked() +{ + return (__sgetc(stdin)); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index 48bb3fb61503..ec17eb1ef3d7 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -1,4 +1,4 @@ -/* $NetBSD: putc.c,v 1.6 1997/07/13 20:15:19 christos Exp $ */ +/* $NetBSD: putc.c,v 1.7 1998/01/19 07:38:51 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,21 +41,36 @@ #if 0 static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: putc.c,v 1.6 1997/07/13 20:15:19 christos Exp $"); +__RCSID("$NetBSD: putc.c,v 1.7 1998/01/19 07:38:51 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" /* * A subroutine version of the macro putc. */ #undef putc +#undef putc_unlocked int putc(c, fp) int c; - register FILE *fp; + FILE *fp; +{ + int r; + + FLOCKFILE(fp); + r = __sputc(c, fp); + FUNLOCKFILE(fp); + return r; +} + +int +putc_unlocked(c, fp) + int c; + FILE *fp; { return (__sputc(c, fp)); } diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index b59e44c81022..2cec6a9c1392 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -1,4 +1,4 @@ -/* $NetBSD: putchar.c,v 1.6 1997/07/13 20:15:19 christos Exp $ */ +/* $NetBSD: putchar.c,v 1.7 1998/01/19 07:38:52 jtc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,13 +41,15 @@ #if 0 static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: putchar.c,v 1.6 1997/07/13 20:15:19 christos Exp $"); +__RCSID("$NetBSD: putchar.c,v 1.7 1998/01/19 07:38:52 jtc Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include "reentrant.h" #undef putchar +#undef putchar_unlocked /* * A subroutine version of the macro putchar @@ -56,7 +58,18 @@ int putchar(c) int c; { - register FILE *so = stdout; + FILE *fp = stdout; + int r; - return (__sputc(c, so)); + FLOCKFILE(fp); + r = __sputc(c, fp); + FUNLOCKFILE(fp); + return r; +} + +int +putchar_unlocked(c) + int c; +{ + return (__sputc(c, stdout)); }