From 2acecd74411762657c5fae5246919db82e7f476c Mon Sep 17 00:00:00 2001 From: tholo Date: Mon, 28 Oct 1996 05:32:54 +0000 Subject: Verify that file pointer is writable --- lib/libc/stdio/fputc.c | 8 +++++++- lib/libc/stdio/putc.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index b7630b1a3a1..ed6c256f5c9 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -35,14 +35,20 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fputc.c,v 1.2 1996/08/19 08:32:42 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fputc.c,v 1.3 1996/10/28 05:32:54 tholo Exp $"; #endif /* LIBC_SCCS and not lint */ #include +#include +#include "local.h" fputc(c, fp) int c; register FILE *fp; { + if (cantwrite(fp)) { + errno = EBADF; + return (EOF); + } return (putc(c, fp)); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index db1edd14bd0..b43af508a55 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -35,10 +35,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: putc.c,v 1.2 1996/08/19 08:32:58 tholo Exp $"; +static char rcsid[] = "$OpenBSD: putc.c,v 1.3 1996/10/28 05:32:55 tholo Exp $"; #endif /* LIBC_SCCS and not lint */ #include +#include +#include "local.h" /* * A subroutine version of the macro putc. @@ -49,5 +51,9 @@ putc(c, fp) int c; register FILE *fp; { + if (cantwrite(fp)) { + errno = EBADF; + return (EOF); + } return (__sputc(c, fp)); } -- cgit v1.2.3-59-g8ed1b