#include #include #include #include #include #include static struct stat st; static time_t mod = 0; static time_t local; void callback_review(char *path) { FILE *file, *k; char buf[4096]; char buf2[4096]; char *p, *p2; file = fopen(path, "r"); if (!file) { fprintf(stderr, "Unable to open %s\n", path); return 1; } fseek(file, -256L, SEEK_END); while (fgets(buf, sizeof(buf), file)) { char line[4096]; strcat(line, buf); p = buf; p2 = buf; while ((*p != 0) && (*p != '\n')) p++; strncpy(line, p2, (p - p2)); line[p - p2] = 0; fprintf(stderr, "%s\n", line); } fflush(stderr); fclose(file); } void timer (int betsec) { time_t now; local = time(NULL); while (now-local < betsec) now = time(NULL); } int main (int argc, char **argv) { char *path; if (argc < 2) { fprintf(stderr, "Missing argument!\n"); return 1; } path = argv[1]; while (1) { timer(2); stat(path, &st); if (st.st_mtime != mod) { callback_review(path); mod = st.st_mtime; } } //test(path); return 0; }