]> git.llucax.com Git - z.facultad/75.06/jacu.git/blobdiff - src/vfile/vfile.c
Hack feo para que no se cuelgue en el fopen de fsize() con archivos multivolumen...
[z.facultad/75.06/jacu.git] / src / vfile / vfile.c
index 589d4aa1212bf1af2ca3fedd95c9f527561164df..469ef768240fab65c6bbc0cb02a7c4befe39d002 100644 (file)
@@ -215,3 +215,54 @@ int vfvol_open_next(VFILE* vfp)
        return 0;
 }
 
        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;
+}
+