diff options
| author | lukem <lukem@NetBSD.org> | 2001-01-25 02:06:25 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 2001-01-25 02:06:25 +0000 |
| commit | fa11ebb1334320acf15ea44bcff6e11bd76b16ab (patch) | |
| tree | 451eccea8ab5835376d923e7baa2a7b2dbc365f3 /lib/libc/stdio/fwrite.c | |
| parent | 7df82ad12b3521804f4402793e70661e67e8b1ec (diff) | |
apparently ansi c only required fread(3) to return 0 if size or nmembs == 0.
however, susv2 adds the same to fwrite(3), so add the explicit check.
document this for both fread & fwrite. move diagassert for buf!=NULL to after
the (size * nmembs) == 0 check.
this has the helpful side effect of preventing the _DIAGASSERT()ion in
fwrite() being triggered by lots of 3rdparty code that calls fwrite() with
buf=NULL count=0
Diffstat (limited to 'lib/libc/stdio/fwrite.c')
| -rw-r--r-- | lib/libc/stdio/fwrite.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 0d45807bd2e..92818b2c512 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwrite.c,v 1.12 1999/09/20 04:39:30 lukem Exp $ */ +/* $NetBSD: fwrite.c,v 1.13 2001/01/25 02:06:25 lukem Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fwrite.c,v 1.12 1999/09/20 04:39:30 lukem Exp $"); +__RCSID("$NetBSD: fwrite.c,v 1.13 2001/01/25 02:06:25 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -66,12 +66,17 @@ fwrite(buf, size, count, fp) struct __suio uio; struct __siov iov; - _DIAGASSERT(buf != NULL); _DIAGASSERT(fp != NULL); + /* + * SUSv2 requires a return value of 0 for a count or a size of 0. + */ + if ((n = count * size) == 0) + return (0); + _DIAGASSERT(buf != NULL); /* LINTED we don't play with buf */ iov.iov_base = (void *)buf; - uio.uio_resid = iov.iov_len = n = count * size; + uio.uio_resid = iov.iov_len = n; uio.uio_iov = &iov; uio.uio_iovcnt = 1; |
