From 2ffb32bcb4df93ac17fd51e4f6497d0c4bd7a9d6 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Thu, 9 Mar 2017 15:22:22 +0000 Subject: [PATCH] skip if file size is changing --- file.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/file.c b/file.c index f83bb5b..7ba334d 100644 --- a/file.c +++ b/file.c @@ -23,7 +23,27 @@ struct epg * open_file(char *filename) { struct epg *epg; - struct stat st; + struct stat st, st2; + + if (debug) + printf("Opening file '%s'\n", filename); + + if (stat(filename, &st) == -1) + { + perror(filename); + return NULL; + } + sleep(1); + if (stat(filename, &st2) == -1) + { + perror(filename); + return NULL; + } + if (st.st_size != st2.st_size) + { + printf("EPG data file is updating, try later.\n"); + return NULL; + } if (!(epg = malloc(sizeof(struct epg)))) { @@ -31,18 +51,7 @@ open_file(char *filename) return NULL; } - if (debug) - printf("Opening file '%s'\n", filename); - strcpy(epg->fname, filename); - - if (stat(epg->fname, &st) == -1) - { - perror(epg->fname); - free(epg); - return NULL; - } - epg->binsize = st.st_size; if (debug)