Wow excellent code newmangj... I can't believe how much less overhead your method has than what I was using previously. It still consumes slightly more resources than tail, but is incredibly more efficient than the err/clearerr method. Not only that, but detection of truncation was something I...
Nevermind I got it working using fgets(), to stop on the endlines and EOFs:
char buf[301];
// Start reading end of log file
fseek(f_read, 0, SEEK_END);
while(1) {
fgets(buf, 301, f_read);
if (feof(f_read)) {
clearerr(f_read);
} else {...
I tried this, and it *almost* works:
char buf[301];
while(1) {
fread(buf, 301, 1, f_read);
if (feof(f_read)) {
clearerr(f_read);
} else {
printf("%s\n",buf);
}
sleep(1);
}
The output is sometimes a single line and...
As I said I'm creating a routine... I'm not intending to recreate tail per se.
The actual goal of the project is to multicast specific log messages to clients on the network. So far the line parsing and multicast server/client are complete and working. The only thing that remains to be done...
I'm attempting to create a C routine that mimics the behavior of "tail -f". The idea is to monitor a log file, and have a function called every time a new line is detected in the log (passing it the new line). This log file could possibly be written many times per second, so speed is a factor...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.