diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-03-30 21:09:08 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-03-30 21:09:08 -0700 |
commit | 95207366218ffadcb7f377db1b5577c758b82149 (patch) | |
tree | 649e220bf4a9fd0a9da9e5dd228d5ea8c17c7ca1 /src/misc/extra/extraUtilFile.c | |
parent | 9eb1be8e537d7826d3bd09d173b7578baa7ec2a3 (diff) | |
download | abc-95207366218ffadcb7f377db1b5577c758b82149.tar.gz abc-95207366218ffadcb7f377db1b5577c758b82149.tar.bz2 abc-95207366218ffadcb7f377db1b5577c758b82149.zip |
Added several new APIs to GIA and for file management.
Diffstat (limited to 'src/misc/extra/extraUtilFile.c')
-rw-r--r-- | src/misc/extra/extraUtilFile.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/misc/extra/extraUtilFile.c b/src/misc/extra/extraUtilFile.c index 4f8af483..5f905814 100644 --- a/src/misc/extra/extraUtilFile.c +++ b/src/misc/extra/extraUtilFile.c @@ -276,6 +276,28 @@ char * Extra_FileRead( FILE * pFile ) pBuffer[ nFileSize + 1] = '\0'; return pBuffer; } +char * Extra_FileRead2( FILE * pFile, FILE * pFile2 ) +{ + char * pBuffer; + int nSize, nSize2; + int RetValue; + // get the file size, in bytes + fseek( pFile, 0, SEEK_END ); + nSize = ftell( pFile ); + rewind( pFile ); + // get the file size, in bytes + fseek( pFile2, 0, SEEK_END ); + nSize2 = ftell( pFile2 ); + rewind( pFile2 ); + // load the contents of the file into memory + pBuffer = ABC_ALLOC( char, nSize + nSize2 + 3 ); + RetValue = fread( pBuffer, nSize, 1, pFile ); + RetValue = fread( pBuffer + nSize, nSize2, 1, pFile2 ); + // terminate the string with '\0' + pBuffer[ nSize + nSize2 + 0] = '\n'; + pBuffer[ nSize + nSize2 + 1] = '\0'; + return pBuffer; +} /**Function************************************************************* @@ -294,8 +316,18 @@ char * Extra_FileReadContents( char * pFileName ) char * pBuffer; pFile = fopen( pFileName, "rb" ); pBuffer = pFile ? Extra_FileRead( pFile ) : NULL; - if ( pFile ) - fclose( pFile ); + if ( pFile ) fclose( pFile ); + return pBuffer; +} +char * Extra_FileReadContents2( char * pFileName, char * pFileName2 ) +{ + FILE * pFile, * pFile2; + char * pBuffer; + pFile = fopen( pFileName, "rb" ); + pFile2 = fopen( pFileName2, "rb" ); + pBuffer = (pFile && pFile2) ? Extra_FileRead2( pFile, pFile2 ) : NULL; + if ( pFile ) fclose( pFile ); + if ( pFile2 ) fclose( pFile2 ); return pBuffer; } |