summaryrefslogtreecommitdiffstats
path: root/src/misc/extra
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-03-11 23:07:27 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-03-11 23:07:27 -0700
commit49c13f4f03d1c7d431236cab5faed973ee6e83ec (patch)
tree25238e075957d4981fb9ad59b3fe333639bb05be /src/misc/extra
parent795b5a6ce794f72be156fa80f36f7671e7966b94 (diff)
downloadabc-49c13f4f03d1c7d431236cab5faed973ee6e83ec.tar.gz
abc-49c13f4f03d1c7d431236cab5faed973ee6e83ec.tar.bz2
abc-49c13f4f03d1c7d431236cab5faed973ee6e83ec.zip
Added new procedures to read files.
Diffstat (limited to 'src/misc/extra')
-rw-r--r--src/misc/extra/extra.h2
-rw-r--r--src/misc/extra/extraUtilFile.c51
2 files changed, 52 insertions, 1 deletions
diff --git a/src/misc/extra/extra.h b/src/misc/extra/extra.h
index 0bef042c..189a4a42 100644
--- a/src/misc/extra/extra.h
+++ b/src/misc/extra/extra.h
@@ -104,8 +104,10 @@ extern char * Extra_FileNameExtension( char * FileName );
extern char * Extra_FileNameAppend( char * pBase, char * pSuffix );
extern char * Extra_FileNameGeneric( char * FileName );
extern char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix );
+extern int Extra_FileCheck( char * pFileName );
extern int Extra_FileSize( char * pFileName );
extern char * Extra_FileRead( FILE * pFile );
+extern char * Extra_FileReadContents( char * pFileName );
extern int Extra_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 );
extern char * Extra_TimeStamp();
extern char * Extra_StringAppend( char * pStrGiven, char * pStrAdd );
diff --git a/src/misc/extra/extraUtilFile.c b/src/misc/extra/extraUtilFile.c
index e2c32ec3..4f8af483 100644
--- a/src/misc/extra/extraUtilFile.c
+++ b/src/misc/extra/extraUtilFile.c
@@ -203,11 +203,38 @@ char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix )
SeeAlso []
***********************************************************************/
+int Extra_FileCheck( char * pFileName )
+{
+ FILE * pFile;
+ pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ {
+ printf( "Extra_FileCheck(): File \"%s\" does not exist.\n", pFileName );
+ return 0;
+ }
+ fseek( pFile, 0, SEEK_END );
+ if ( ftell( pFile ) == 0 )
+ printf( "Extra_FileCheck(): File \"%s\" is empty.\n", pFileName );
+ fclose( pFile );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns the file size.]
+
+ Description [The file should be closed.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int Extra_FileSize( char * pFileName )
{
FILE * pFile;
int nFileSize;
- pFile = fopen( pFileName, "r" );
+ pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" );
@@ -252,6 +279,28 @@ char * Extra_FileRead( FILE * pFile )
/**Function*************************************************************
+ Synopsis [Read the file into the internal buffer.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Extra_FileReadContents( char * pFileName )
+{
+ FILE * pFile;
+ char * pBuffer;
+ pFile = fopen( pFileName, "rb" );
+ pBuffer = pFile ? Extra_FileRead( pFile ) : NULL;
+ if ( pFile )
+ fclose( pFile );
+ return pBuffer;
+}
+
+/**Function*************************************************************
+
Synopsis [Returns one if the file has a given extension.]
Description []