From bd0062922151710408edae80d0f67db20114c6c9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 27 Jun 2004 00:46:43 +0000 Subject: [PATCH 1/1] =?utf8?q?Se=20agrega=20vfsize()=20para=20obtener=20el?= =?utf8?q?=20tama=C3=B1o=20de=20un=20archivo=20multivolumen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/vfile/vfile.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ src/vfile/vfile.h | 3 +++ 2 files changed, 54 insertions(+) diff --git a/src/vfile/vfile.c b/src/vfile/vfile.c index 589d4aa..469ef76 100644 --- a/src/vfile/vfile.c +++ b/src/vfile/vfile.c @@ -215,3 +215,54 @@ int vfvol_open_next(VFILE* vfp) return 0; } +long vfsize(const char* path) +{ + VFILE* vfp = vfopen(path, "r", 0); + long size; + if (!vfp) return -1; /* error */ + if (fseek(vfp->fp, 0l, SEEK_END) == -1) + { + vfclose(vfp); + return -1; /* error */ + } + else + { + size = ftell(vfp->fp); + if (size == -1) + { + vfclose(vfp); + return -1; /* error */ + } + } + while (!vfp->lastvol) /* mientras no sea el último volumen */ + { + if (vfvol_open_next(vfp)) + { + vfclose(vfp); + return -1; /* error */ + } + if (fseek(vfp->fp, 0l, SEEK_END) == -1) + { + vfclose(vfp); + return -1; /* error */ + } + else + { + long curr_size = ftell(vfp->fp); + if (curr_size == -1) + { + vfclose(vfp); + return -1; /* error */ + } + size += curr_size; + } + if (vfvol_close(vfp)) + { + vfclose(vfp); + return -1; /* error */ + } + } + vfclose(vfp); + return size; +} + diff --git a/src/vfile/vfile.h b/src/vfile/vfile.h index 7b03604..ad4f0c1 100644 --- a/src/vfile/vfile.h +++ b/src/vfile/vfile.h @@ -103,5 +103,8 @@ size_t vfwrite(const void *ptr, size_t size, size_t nmemb, VFILE* vfp); /** Indica si es el fin del archivo multivolumen. */ int vfeof(VFILE* vfp); +/** Obtiene el tamaño de un archivo virtual multivolumen. */ +long vfsize(const char* path); + #endif /* _JACU_VFILE_H_ */ -- 2.43.0