* Autores: Leandro Lucarella <llucare@fi.uba.ar>
*----------------------------------------------------------------------------
*
- * $Id: bufford.c 624 2004-05-30 20:18:04Z llucare $
+ * $Id$
*
*/
return ret;
}
+int vfeof(VFILE* vfp)
+{
+ return vfp->lastvol && feof(vfp->fp);
+}
+
int vfgetc(VFILE* vfp)
{
int c;
size_t vfread(void* ptr, size_t size, size_t nmemb, VFILE* vfp)
{
- int i;
+ int c;
+ size_t i = 0;
size_t total = size * nmemb;
/* leo uno a uno y si hay error salgo. */
- for (i = 0; i < total && (((char*)ptr)[i] = vfgetc(vfp)) != EOF; ++i);
- 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;
+ size_t i = 0;
size_t total = size * nmemb;
/* escribo uno a uno y si hay error salgo. */
- for (i = 0; i < total && (vfputc(((char*)ptr)[i], vfp)) != EOF; ++i);
- return i % size;
+ while (i < total && (vfputc(((char*)ptr)[i++], vfp)) != EOF);
+ return i / size;
}
int vfvol_close(VFILE* vfp)