Fix fwrite() to return 0 when size or nmemb are zero.
Right now nmemb is returned when size is 0. In newer versions of the standards, it is explicitly required that fwrite() should return 0. Submitted by: Christoph Mallon Approved by: re (kib)
This commit is contained in:
parent
5861f96654
commit
77822acff7
@ -67,9 +67,7 @@ __fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
|
||||
size_t total;
|
||||
|
||||
/*
|
||||
* The ANSI standard requires a return value of 0 for a count
|
||||
* or a size of 0. Peculiarily, it imposes no such requirements
|
||||
* on fwrite; it only requires fread to be broken.
|
||||
* ANSI and SUSv2 require a return value of 0 if size or count are 0.
|
||||
*/
|
||||
if ((resid = count * size) == 0)
|
||||
return (0);
|
||||
|
@ -57,8 +57,15 @@ fwrite(buf, size, count, fp)
|
||||
struct __suio uio;
|
||||
struct __siov iov;
|
||||
|
||||
/*
|
||||
* ANSI and SUSv2 require a return value of 0 if size or count are 0.
|
||||
*/
|
||||
n = count * size;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
|
||||
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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user