From 7fe99d86e55a363a603d271e7952e4ba93246cc9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 21 Jun 2004 00:46:08 +0000 Subject: [PATCH 1/1] Bugfix. vfread() ya anda bien. --- src/vfile/vfile.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/vfile/vfile.c b/src/vfile/vfile.c index bba064f..589d4aa 100644 --- a/src/vfile/vfile.c +++ b/src/vfile/vfile.c @@ -132,20 +132,29 @@ int vfputc(int c, VFILE* vfp) size_t vfread(void* ptr, size_t size, size_t nmemb, VFILE* vfp) { - int i = 0; + int c; + size_t i = 0; size_t total = size * nmemb; /* leo uno a uno y si hay error salgo. */ - while (i < total && (((char*)ptr)[i++] = vfgetc(vfp)) != EOF); - return i % size; + while (i < total) + { + if ((c = vfgetc(vfp)) == EOF) + { + PERR("vfread: EOF"); + break; + } + else ((char*)ptr)[i++] = c; + } + return i / size; } size_t vfwrite(const void *ptr, size_t size, size_t nmemb, VFILE* vfp) { - int i = 0; + size_t i = 0; size_t total = size * nmemb; /* escribo uno a uno y si hay error salgo. */ while (i < total && (vfputc(((char*)ptr)[i++], vfp)) != EOF); - return i % size; + return i / size; } int vfvol_close(VFILE* vfp) -- 2.43.0