Commit fa22ffb4 by Celine Mercier

Added an error check when reading an input file

parent 04912948
...@@ -44,7 +44,7 @@ FILE *file_openrw(char* fileName, BOOL abortOnError) ...@@ -44,7 +44,7 @@ FILE *file_openrw(char* fileName, BOOL abortOnError)
/* /*
* Function Name: fileNextChar(FILE* fp) * Function Name: fileNextChar(FILE* fp)
* Description: Reads the file and returns next character, if file is null or its end of file, returns \. * Description: Reads the file and returns next character, if file is null or its end of file, returns \.
*/ */
char file_nextChar(FILE* fp) char file_nextChar(FILE* fp)
{ {
...@@ -59,7 +59,7 @@ char file_nextChar(FILE* fp) ...@@ -59,7 +59,7 @@ char file_nextChar(FILE* fp)
/* /*
* Function Name: *fileNextLine(FILE *fp, char *buffer, int32_t bufferSize) * Function Name: *fileNextLine(FILE *fp, char *buffer, int32_t bufferSize)
* Description: Reads the file and returns next line, if file is null or its end of file, returns \. * Description: Reads the file and returns next line, if file is null or its end of file, returns \.
*/ */
char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize) char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize)
{ {
...@@ -76,7 +76,11 @@ char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize) ...@@ -76,7 +76,11 @@ char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize)
void exitIfEmptyFile(FILE *file) void exitIfEmptyFile(FILE *file)
{ {
long savedOffset = ftell(file); long savedOffset = ftell(file);
fseek(file, 0, SEEK_END); if (fseek(file, 0, SEEK_END) != 0)
{
fprintf(stderr, "\nError moving the offset in an input file\n");
exit(1);
}
if (ftell(file) == 0) if (ftell(file) == 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment