mirror of
https://github.com/parkervcp/eggs.git
synced 2024-11-25 23:33:00 +08:00
wrapper use time and not size
This commit is contained in:
parent
bf1217839d
commit
9c08f3fd5e
Binary file not shown.
@ -8,7 +8,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_size) {
|
void print_latest_log(const char* log_directory, off_t* last_pos, time_t* last_time) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
time_t latest_time = 0;
|
time_t latest_time = 0;
|
||||||
@ -39,19 +39,18 @@ void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_si
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (latest_time <= *last_time) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int fd = open(latest_file, O_RDONLY);
|
int fd = open(latest_file, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("Error opening file %s\n", latest_file);
|
printf("Error opening file %s\n", latest_file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the size of the file
|
// Move the file pointer to the last printed position
|
||||||
off_t size = lseek(fd, 0, SEEK_END);
|
lseek(fd, *last_pos, SEEK_SET);
|
||||||
|
|
||||||
// Check if the file size has increased since the last read
|
|
||||||
if (size > *last_size) {
|
|
||||||
// Move the file pointer to the beginning of the file
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
@ -81,16 +80,16 @@ void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_si
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember the last position and size that was read
|
// Remember the last position and time that was read
|
||||||
*last_pos = lseek(fd, 0, SEEK_CUR);
|
*last_pos = lseek(fd, 0, SEEK_CUR);
|
||||||
*last_size = size;
|
*last_time = latest_time;
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Usage: winewrapper wine_path wine_args exe_path exe_args\n");
|
printf("Usage: winewrapper wine_path wine_args exe_path exe_args\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user