If what you want to do is similar to the Log Viewer of Red Hat., I'd recommend that you fopen(3) the log file (/var/log/syslog for instance), fseek(3) 10 kilo bytes from the end of the file, loop with fgets(3) until the end of the file (discard the first line which is likely to be partially filled), ftell(3) to know the byte ofset of the end of the file and memorize it, fclose(3). After sleeping for a second or two, fopen(3) again and do the same, starting from the memorized offset given by ftell(3).
There are some tricky issues to address all the problems (log rotating etc.). It might be a lot easier to cut/paste code from GNU tail(1), provided you intend to release your software under a license that is compatible with the GNU GPL.
|