]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - util.c
Keep global statistics in memory and use them to check computation
[thirdparty/sarg.git] / util.c
diff --git a/util.c b/util.c
index 750017a4fbdb604771ba79c44a8ce4650c838c89..280746097b6c0ef5cf9aba34e09178adcaa9db81 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1281,10 +1281,8 @@ char *strup(char *string)
 
 void removetmp(const char *outdir)
 {
-       FILE *fp_in;
-       char warea[256];
-       char buf[MAXLEN];
-       long pos;
+       FILE *fp_gen;
+       char filename[256];
 
        if(!RemoveTempFiles)
                return;
@@ -1292,38 +1290,19 @@ void removetmp(const char *outdir)
        if(debug) {
                debuga(_("Purging temporary file sarg-general\n"));
        }
-       if (snprintf(warea,sizeof(warea),"%s/sarg-general",outdir)>=sizeof(warea)) {
+       if (snprintf(filename,sizeof(filename),"%s/sarg-general",outdir)>=sizeof(filename)) {
                debuga(_("(removetmp) directory too long to remove %s/sarg-period\n"),outdir);
                exit(EXIT_FAILURE);
        }
-       if((fp_in=fopen(warea,"r+"))==NULL){
-               debuga(_("(removetmp) Cannot open file %s\n"),warea);
-               exit(EXIT_FAILURE);
-       }
-       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-               if(strncmp(buf,"TOTAL",5) == 0 && (buf[6]=='\t' || buf[6]==' '))
-                       break;
-       }
-       if (fseek(fp_in,0,SEEK_SET)==-1) {
-               debuga(_("Failed to rewind to the beginning of the file %s: %s\n"),warea,strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-
-       if (fputs(buf,fp_in)==EOF) {
-               debuga(_("Failed to write the total line in %s - %s\n"),warea,strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-       pos=ftell(fp_in);
-       if (pos>0 && ftruncate(fileno(fp_in),pos)==-1) {
-               debuga(_("Failed to truncate %s: %s\n"),warea,strerror(errno));
+       if((fp_gen=fopen(filename,"w"))==NULL){
+               debuga(_("(removetmp) Cannot open file %s\n"),filename);
                exit(EXIT_FAILURE);
        }
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Failed to close %s after writing the total line - %s\n"),warea,strerror(errno));
+       totalger(fp_gen,filename);
+       if (fclose(fp_gen)==EOF) {
+               debuga(_("Failed to close %s after writing the total line - %s\n"),filename,strerror(errno));
                exit(EXIT_FAILURE);
        }
-
-       return;
 }
 
 void load_excludecodes(const char *ExcludeCodes)