--- SRC/consume.c.orig +++ SRC/consume.c @@ -140,7 +140,7 @@ consumeUptoBreak { break; /* line break detected */ } - else if( *buffer == EOF ) + else if( *buffer == 0 ) { break; /* End-Of-File detected */ } --- SRC/file.c.orig +++ SRC/file.c @@ -35,18 +35,34 @@ readFile File_t returnValue; FILE * filePointer; long fileLength; - char * buffer = NULL; if( FileOpened == openFileForReading( filename, &filePointer ) ) { if( Success == getFileLength( filePointer, &fileLength ) ) { - if( Success == - allocateBuffer( fileLength, ( void ** )&buffer ) ) + void * ptr; + + /* + * Allocate one byte more if a newline must be added + */ + if( Success == allocateBuffer( fileLength + 1 , &ptr ) ) { - if( Success == - readFileToBuffer( filePointer, fileLength, &buffer ) ) - { + char * buffer = ( char * )ptr; + + if( Success == readFileToBuffer( filePointer, fileLength, &buffer ) ) + { + + if ( FALSE == queryParameter( IgnoreEOF ) ) + { + char * eof = (buffer + fileLength - 1); + + if ( *eof != '\n' ) + { + *( eof + 1 ) = '\n'; + fileLength++; + } + } + addToWatchdog( fileLength ); associateBuffer( fileSpecifier, fileLength, &buffer ); returnValue = FileOperationsSuccessful; --- SRC/parameters.c.orig +++ SRC/parameters.c @@ -368,6 +368,13 @@ queryParameter } break; + case IgnoreEOF: + if( parameterIgnoreEOF == IsSet ) + { + returnValue = TRUE; + } + break; + case IgnoreDefinites: if( parameterIgnoreDefinites == IsSet ) { --- SRC/parser.c.orig +++ SRC/parser.c @@ -19,7 +19,7 @@ /*--------------------------------- IMPORTS ----------------------------------*/ #include - +#include #include "portab.h" #include "variableblock.h" #include "parameters.h" @@ -296,6 +296,7 @@ createAdministrationInfo unsigned long Size; char * delimiterString; char delimiterChar; + void * ptr; queryStringParameter( Delimiter, &delimiterString ); delimiterChar = delimiterString[ 0 ]; @@ -305,23 +306,25 @@ createAdministrationInfo countDelimiters( delimiterChar, baseFileBuffer, baseFileBufferLength ); baseFileBlocksLength++; /* add possible trailing comment */ Size = baseFileBlocksLength * sizeof( VariableBlock_t ); - if( Success != allocateBuffer( Size, ( void ** )&baseFileBlock ) ) + if( Success != allocateBuffer( Size, &ptr ) ) { fillup_exception( __FILE__, __LINE__, ConfigurationException, "createAdministrationInfo" ); exitOnFailure( ); } + baseFileBlock = ( VariableBlock_t * )ptr; additionalFileBlocksLength = countDelimiters( delimiterChar, additionalFileBuffer, additionalFileBufferLength ); additionalFileBlocksLength++; /* add possible trailing comment */ Size = additionalFileBlocksLength * sizeof( VariableBlock_t ); - if( Success != allocateBuffer( Size, ( void ** )&additionalFileBlock ) ) + if( Success != allocateBuffer( Size, &ptr ) ) { fillup_exception( __FILE__, __LINE__, ConfigurationException, "createAdministrationInfo" ); exitOnFailure( ); } + additionalFileBlock = ( VariableBlock_t * )ptr; if( queryParameter( ForbiddenFile ) == TRUE ) { @@ -329,12 +332,13 @@ createAdministrationInfo delimiterChar, forbiddenFileBuffer, forbiddenFileBufferLength ); forbiddenFileBlocksLength++; /* add possible trailing comment */ Size = forbiddenFileBlocksLength * sizeof( VariableBlock_t ); - if( Success != allocateBuffer( Size, ( void ** )&forbiddenFileBlock ) ) + if( Success != allocateBuffer( Size, &ptr ) ) { fillup_exception( __FILE__, __LINE__, ConfigurationException, "createAdministrationInfo" ); exitOnFailure( ); } + forbiddenFileBlock = ( VariableBlock_t * )ptr; } } @@ -477,8 +481,8 @@ getVariable getVBeginOfBlock( outputBuffer, &Line ); Line = Line + getVLength( outputBuffer ); LinePointer = Line; - for( lineIndex = 0; - ( *LinePointer != EOF ) && ( *LinePointer != '\n' ); + for( lineIndex = 0; + ( *LinePointer != 0 ) && ( *LinePointer != '\n' ) ; lineIndex++ ) { LinePointer++; /* concerns only the current line */ @@ -1768,6 +1772,8 @@ writeOutput } listPointer++; } + if(fflush( filePointer ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot flush stream"); + if(fdatasync ( fileno(filePointer) ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot sync stream"); closeFile( filePointer ); } } @@ -1830,7 +1836,9 @@ writeOutput default: break; } listPointer++; - } + } + if(fflush( filePointer ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot flush stream"); + if(fdatasync ( fileno(filePointer) ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot sync stream"); closeFile( filePointer ); } } --- SRC/services.c.orig +++ SRC/services.c @@ -444,8 +444,9 @@ readFileToBuffer if( 0 == fseek( filePointer, 0L, SEEK_SET ) ) { - if( fileLength == - ( long )fread( *fileBuffer, sizeof( char ), fileLength, filePointer ) ) + if( ( fileLength == + ( long )fread( *fileBuffer, sizeof( char ), fileLength, filePointer ) ) + && ( 0 == ferror( filePointer ) ) ) { returnValue = Success; } @@ -558,23 +559,22 @@ dumpBlock Service_t allocateBuffer ( - long fileLength, /* in */ + long Length, /* in */ void ** buffer /* out */ ) { Service_t returnValue; - *buffer = malloc( fileLength + 1 ); + *buffer = malloc( Length + 1 ); if( *buffer == NULL ) { - fillup_exception( __FILE__, __LINE__, ServiceException, - "malloc" ); + fillup_exception( __FILE__, __LINE__, ServiceException, "malloc" ); returnValue = Error; } else { /* reset the buffer */ - ( void )memset( *buffer, EOF, fileLength + 1 ); + ( void )memset( *buffer, 0, Length + 1 ); returnValue = Success; } --- SRC/metadata.c.orig +++ SRC/metadata.c @@ -17,7 +17,7 @@ /*--------------------------------- IMPORTS ----------------------------------*/ #include - +#include #include "variableblock.h" #include "services.h" #include "parser.h" @@ -392,7 +392,8 @@ setMetadataInfo logfile ); fprintf( logfile, ">\n\n" ); } - + if(fflush( logfile ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot flush stream"); + if(fdatasync( fileno(logfile) ) != 0) fillup_exception( __FILE__, __LINE__, ServiceException, "cannot sync stream"); closeFile( logfile ); } }