]> git.ipfire.org Git - thirdparty/sarg.git/blob - totger.c
a521b774fbf046ecc798b2ea7f25f2e6dc46bdc8
[thirdparty/sarg.git] / totger.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 int totalger(const char *dirname, int debug, const char *outdir)
31 {
32 FILE *fp_in;
33 long long int tnacc=0;
34 long long int tnbytes=0;
35 long long int telap=0;
36 long long int tincache=0, toucache=0;
37 char wger[MAXLEN];
38 char *warea;
39 longline line;
40 struct generalitemstruct item;
41
42 snprintf(wger,sizeof(wger),"%s/sarg-general",dirname);
43 if((fp_in=fopen(wger,"r+"))==NULL) {
44 debuga(_("(totger) Cannot open file %s\n"),wger);
45 exit(EXIT_FAILURE);
46 }
47
48 if ((line=longline_create())==NULL) {
49 debuga(_("Not enough memory to read the temporary file %s\n"),wger);
50 exit(EXIT_FAILURE);
51 }
52
53 while((warea=longline_read(fp_in,line))!=NULL)
54 {
55 ger_read(warea,&item,wger);
56 tnacc+=item.nacc;
57 tnbytes+=item.nbytes;
58 telap+=item.nelap;
59 tincache+=item.incache;
60 toucache+=item.oucache;
61 }
62
63 longline_destroy(&line);
64
65 if (fseek(fp_in,0,SEEK_END)==-1) {
66 debuga(_("Failed to move to the end of %s - %s\n"),wger,strerror(errno));
67 exit(EXIT_FAILURE);
68 }
69
70 /*
71 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
72 to print a long long int unless it is exactly 64-bits long.
73 */
74 if (fprintf(fp_in,"TOTAL\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)tnacc,(uint64_t)tnbytes,(uint64_t)telap,(uint64_t)tincache,(uint64_t)toucache)<0) {
75 debuga(_("Failed to write the total line in %s\n"),wger);
76 exit(EXIT_FAILURE);
77 }
78 if (fclose(fp_in)==EOF) {
79 debuga(_("Failed to close file %s - %s\n"),wger,strerror(errno));
80 exit(EXIT_FAILURE);
81 }
82
83 return (0);
84 }