From: Frederic Marchal Date: Sun, 12 Jul 2015 19:14:59 +0000 (+0200) Subject: Send email report directly to stdout X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dced089e59c2f0cc729654e19a84d4547b24456;p=thirdparty%2Fsarg.git Send email report directly to stdout If the email report must be sent to stdout, do it directly. Don't use another temporary file simply to output it later to stdout. --- diff --git a/email.c b/email.c index 6e46807..565c68a 100644 --- a/email.c +++ b/email.c @@ -154,10 +154,14 @@ int geramail(const char *dirname, int debug, const char *email, const char *Temp exit(EXIT_FAILURE); } - snprintf(top3,sizeof(top3),"%s/report",dirname); - if((fp_top3=fopen(top3,"w"))==NULL) { - debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); - exit(EXIT_FAILURE); + if(strcmp(email,"stdout") == 0) { + fp_top3=stdout; + } else { + snprintf(top3,sizeof(top3),"%s/report",dirname); + if((fp_top3=fopen(top3,"w"))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); + exit(EXIT_FAILURE); + } } safe_strcpy(strip1,_("Squid User Access Report"),sizeof(strip1)); @@ -267,24 +271,12 @@ int geramail(const char *dirname, int debug, const char *email, const char *Temp local = localtime(&t); fprintf(fp_top3, "\n%s\n", asctime(local)); - if (fclose(fp_top3)==EOF) { - debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); - exit(EXIT_FAILURE); - } - - if(strcmp(email,"stdout") == 0) { - if((fp_top3=fopen(top3,"r"))==NULL) { - debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); - exit(EXIT_FAILURE); - } - - while(fgets(warea,sizeof(warea),fp_top3)!=NULL) - fputs(warea,stdout); + if(strcmp(email,"stdout") != 0) { if (fclose(fp_top3)==EOF) { - debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top3,strerror(errno)); + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno)); exit(EXIT_FAILURE); } - } else { + /* TRANSLATORS: The string is formatted using strftime. You can use any string formatting marker allowed by strftime. */ strftime(Subject,sizeof(Subject),_("SARG report, %c"),local);