Reading a Potentially incomplete File C++ -


i writing program reformat dns log file insertion database. there possibility line being written in log file incomplete. if is, discard it.

i started off believing eof function might fit application, noticed lot of programmers dissuading use of eof function. have noticed feof function seems quite similar.

any suggestions/explanations guys provide side effects of these functions appreciated, suggestions more appropriate methods!

edit: using istream::peek function in order skip on last line, regardless of whether complete or not. while acceptable, solution determines whether last line complete preferred.

the specific comparison i'm using is: logfile.peek() != eof

i consider using

int fseek ( file * stream, long int offset, int origin ); 

with seek_end

and

long int ftell ( file * stream ); 

to determine number of bytes in file, , therefore - ends. have found more reliable in detecting end of file (in bytes).

could detect (end of record/line) eor marker (crlf perhaps) in last 2 or 3 bytes of file? (3 bytes might used crlf^z...depends on file type). verify if have complete last row

fseek (stream, -2,seek_end); fread (2 bytes... etc 

if try open file exclusive locks, can detect (by failure open) file in use, , try again in second...(or whenever)


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -