rearranging code to allow for consts

This commit is contained in:
Paul Cruz 2017-06-15 16:12:04 -07:00
parent e49afae2ab
commit 0757eae6ff

View File

@ -877,6 +877,7 @@ typedef struct {
* if successful, returns 0, otherwise returns 1
*/
static int getFileInfo(fileInfo_t* info, const char* inFileName){
int detectError = 0;
FILE* const srcFile = FIO_openSrcFile(inFileName);
if (srcFile == NULL) {
DISPLAY("Error: could not open source file %s\n", inFileName);
@ -887,7 +888,6 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
info->numActualFrames = 0;
info->numSkippableFrames = 0;
info->canComputeDecompSize = 1;
int detectError = 0;
/* begin analyzing frame */
for( ; ; ){
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
@ -902,6 +902,7 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
break;
}
}
{
U32 const magicNumber = MEM_readLE32(headerBuffer);
if (magicNumber == ZSTD_MAGICNUMBER) {
U64 const frameContentSize = ZSTD_getFrameContentSize(headerBuffer, numBytesRead);
@ -911,15 +912,14 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
else {
info->decompressedSize += frameContentSize;
}
{
/* move to the end of the frame header */
size_t const headerSize = ZSTD_frameHeaderSize(headerBuffer, numBytesRead);
if (ZSTD_isError(headerSize)) {
DISPLAY("Error: could not determine frame header size\n");
detectError = 1;
break;
}
{
/* move to the end of the frame header */
int const ret = fseek(srcFile, ((long)headerSize)-((long)numBytesRead), SEEK_CUR);
if (ret != 0) {
DISPLAY("Error: could not move to end of frame header\n");
@ -985,8 +985,8 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
detectError = 1;
break;
}
long const frameSize = MEM_readLE32(frameSizeBuffer);
{
long const frameSize = MEM_readLE32(frameSizeBuffer);
int const ret = fseek(srcFile, frameSize, SEEK_CUR);
if (ret != 0) {
DISPLAY("Error: could not find end of skippable frame\n");
@ -994,10 +994,10 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
break;
}
}
fseek(srcFile, frameSize, SEEK_CUR);
info->numSkippableFrames++;
}
}
}
fclose(srcFile);
return detectError;
}
@ -1036,8 +1036,8 @@ static void displayInfo(const char* inFileName, fileInfo_t* info, int displayLev
}
int FIO_listFile(const char* inFileName, int displayLevel){
DISPLAYOUT("File: %s\n", inFileName);
fileInfo_t info;
DISPLAYOUT("File: %s\n", inFileName);
int const error = getFileInfo(&info, inFileName);
if (error == 1) {
DISPLAY("An error occurred with getting file info\n");