move along, this is not the post you are looking for.
Had a hard to track down bug today where some code that was supposed to return the last line of a log file failed - the logs had recently been rotated and the new file had no lines in it yet. I modified it to create a pointer to the beginning of the file and break out of the infinite loop if the pointer cursor ever gets back to the beginning of the file. With a few minor changes it will work in C C++ C# or Java as they all have something similar to fseek, ftell fclose etc
/**
*
* Reads the last line of a, presumably large, logfile
* without loading the whole file into memory
* Safe to use for 0 or 1 line files
*
*
* @param string
* @return string
*
*/
function readlastline($fileName)
{
$fp = @fopen($fileName, "r");
$begining = fseek($fp, 0);
$pos = -1;
$t = " ";
while ($t != "\n") {
fseek($fp, $pos, SEEK_END);
if(ftell($fp) == $begining){
break;
}
$t = fgetc($fp);
$pos = $pos - 1;
}
$t = fgets($fp);
fclose($fp);
return $t;
}