diff options
| author | lukem <lukem@NetBSD.org> | 1999-09-16 11:44:54 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 1999-09-16 11:44:54 +0000 |
| commit | b48252f3655d61e52b0915f9a89e514d7be3ff24 (patch) | |
| tree | d8f2482fff40eeef4c95e4673d6143575440bba1 /lib/libc/stdio/setbuffer.c | |
| parent | d21225500feaf0f256476f2af8ea342f90c44031 (diff) | |
* use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.
the first two items result in the addition of code similar to the
following in various functions:
_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
Diffstat (limited to 'lib/libc/stdio/setbuffer.c')
| -rw-r--r-- | lib/libc/stdio/setbuffer.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c index b30d8c8d503..8648b0ac457 100644 --- a/lib/libc/stdio/setbuffer.c +++ b/lib/libc/stdio/setbuffer.c @@ -1,4 +1,4 @@ -/* $NetBSD: setbuffer.c,v 1.7 1998/11/15 17:19:53 christos Exp $ */ +/* $NetBSD: setbuffer.c,v 1.8 1999/09/16 11:45:30 lukem Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,10 +41,12 @@ #if 0 static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: setbuffer.c,v 1.7 1998/11/15 17:19:53 christos Exp $"); +__RCSID("$NetBSD: setbuffer.c,v 1.8 1999/09/16 11:45:30 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#include <assert.h> +#include <errno.h> #include <stdio.h> void @@ -54,6 +56,15 @@ setbuffer(fp, buf, size) int size; { + _DIAGASSERT(fp != NULL); + /* buf may be NULL */ +#ifdef _DIAGNOSTIC + if (fp == NULL) { + errno = EBADF; + return; + } +#endif + (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); } @@ -65,5 +76,13 @@ setlinebuf(fp) FILE *fp; { + _DIAGASSERT(fp != NULL); +#ifdef _DIAGNOSTIC + if (fp == NULL) { + errno = EBADF; + return (EOF); + } +#endif + return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); } |
