mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix return value for fread/fwrite when size argument is 0
when the size argument was zero but nmemb was nonzero, these functions were returning nmemb, despite no data having been written. conceptually this is not wrong, but the standard requires a return value of zero in this case.
This commit is contained in:
parent
416d1c7a71
commit
500c6886c6
2 changed files with 2 additions and 0 deletions
|
@ -7,6 +7,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
|
||||||
{
|
{
|
||||||
unsigned char *dest = destv;
|
unsigned char *dest = destv;
|
||||||
size_t len = size*nmemb, l = len, k;
|
size_t len = size*nmemb, l = len, k;
|
||||||
|
if (!size) nmemb = 0;
|
||||||
|
|
||||||
FLOCK(f);
|
FLOCK(f);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
|
||||||
size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f)
|
size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f)
|
||||||
{
|
{
|
||||||
size_t k, l = size*nmemb;
|
size_t k, l = size*nmemb;
|
||||||
|
if (!size) nmemb = 0;
|
||||||
FLOCK(f);
|
FLOCK(f);
|
||||||
k = __fwritex(src, l, f);
|
k = __fwritex(src, l, f);
|
||||||
FUNLOCK(f);
|
FUNLOCK(f);
|
||||||
|
|
Loading…
Add table
Reference in a new issue