Consider the following tail-f style code:
void check_for_new_lines(Stdio.FILE f) { while (string l = f->gets()) { // do something with l. } call_out(check_for_new_lines, 1, f); }
The above currently works fine as long as the file always ends with a line-feed, but if the last line hasn't been fully written to the file, gets() will still return the partial line as if it was complete, with no indication whether the line was partial or not. When the rest of the line is written, gets() will return the remainder, but not the start of the line. With my modified gets():
void check_for_new_lines(Stdio.FILE f) { while (string l = f->gets(1)) { // do something with l. } call_out(check_for_new_lines, 1, f); }
gets() will not return the partial line, but instead keep it in the buffer so that the next time it gets called the complete line can be returned.