From 0b6966fa0613e7c6f754b236074b7b2659ca3744 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 23 Aug 2002 01:52:59 +0000 Subject: [PATCH] add cfile_size function --- cfile/cfile.c | 22 ++++++++++++++++++---- include/cfile.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cfile/cfile.c b/cfile/cfile.c index c86847e9..c5c5dd65 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -1,4 +1,4 @@ -/* $Id: cfile.c,v 1.6 2002-08-01 23:28:57 btb Exp $ */ +/* $Id: cfile.c,v 1.7 2002-08-23 01:52:59 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -18,6 +18,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include #include +#include #include "pstypes.h" #include "u_mem.h" @@ -28,9 +29,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "byteswap.h" typedef struct hogfile { - char name[13]; - int offset; - int length; + char name[13]; + int offset; + int length; } hogfile; #define MAX_HOGFILES 300 @@ -187,6 +188,19 @@ int cfile_init(char *hogname) } +int cfile_size(char *hogname) +{ + CFILE *fp; + struct stat statbuf; + + fp = cfopen(hogname, "rb"); + if (fp == NULL) + return -1; + fstat(fileno(fp->file), &statbuf); + cfclose(fp); + return statbuf.st_size; +} + FILE * cfile_find_libfile(char * name, int * length) { FILE * fp; diff --git a/include/cfile.h b/include/cfile.h index a2f747f6..01de5ea1 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -29,6 +29,8 @@ typedef struct CFILE { //Specify the name of the hogfile. Returns 1 if hogfile found & had files int cfile_init(char *hogname); +int cfile_size(char *hogname); + CFILE * cfopen(char * filename, char * mode); int cfilelength( CFILE *fp ); // Returns actual size of file... size_t cfread( void * buf, size_t elsize, size_t nelem, CFILE * fp ); -- 2.39.2