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.
diff --git a/src/stdio/fread.c b/src/stdio/fread.c
index 33a65f5..aef75f7 100644
--- a/src/stdio/fread.c
+++ b/src/stdio/fread.c
@@ -7,6 +7,7 @@
{
unsigned char *dest = destv;
size_t len = size*nmemb, l = len, k;
+ if (!size) nmemb = 0;
FLOCK(f);
diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c
index fa30c0d..7a567b2 100644
--- a/src/stdio/fwrite.c
+++ b/src/stdio/fwrite.c
@@ -28,6 +28,7 @@
size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f)
{
size_t k, l = size*nmemb;
+ if (!size) nmemb = 0;
FLOCK(f);
k = __fwritex(src, l, f);
FUNLOCK(f);