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;
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)