1*4286Seric # include "sendmail.h"
2*4286Seric 
3*4286Seric static char	SccsId[] =	"@(#)stats.c	3.1	08/31/81";
4*4286Seric 
5*4286Seric /*
6*4286Seric **  POSTSTATS -- post statistics in the statistics file
7*4286Seric **
8*4286Seric **	Parameters:
9*4286Seric **		sfile -- the name of the statistics file.
10*4286Seric **
11*4286Seric **	Returns:
12*4286Seric **		none.
13*4286Seric **
14*4286Seric **	Side Effects:
15*4286Seric **		merges the Stat structure with the sfile file.
16*4286Seric */
17*4286Seric 
18*4286Seric struct statistics	Stat;
19*4286Seric 
20*4286Seric poststats(sfile)
21*4286Seric 	char *sfile;
22*4286Seric {
23*4286Seric 	register int fd;
24*4286Seric 	struct statistics stat;
25*4286Seric 
26*4286Seric 	time(&Stat.stat_itime);
27*4286Seric 	Stat.stat_size = sizeof Stat;
28*4286Seric 
29*4286Seric 	fd = open(sfile, 2);
30*4286Seric 	if (fd < 0)
31*4286Seric 		return;
32*4286Seric 	if (read(fd, &stat, sizeof stat) == sizeof stat &&
33*4286Seric 	    stat.stat_size == sizeof stat)
34*4286Seric 	{
35*4286Seric 		/* merge current statistics into statfile */
36*4286Seric 		register int i;
37*4286Seric 
38*4286Seric 		for (i = 0; i < MAXMAILERS; i++)
39*4286Seric 		{
40*4286Seric 			stat.stat_nf[i] += Stat.stat_nf[i];
41*4286Seric 			stat.stat_bf[i] += Stat.stat_bf[i];
42*4286Seric 			stat.stat_nt[i] += Stat.stat_nt[i];
43*4286Seric 			stat.stat_bt[i] += Stat.stat_bt[i];
44*4286Seric 		}
45*4286Seric 	}
46*4286Seric 	else
47*4286Seric 		bmove(&Stat, &stat, sizeof stat);
48*4286Seric 
49*4286Seric 	/* write out results */
50*4286Seric 	lseek(fd, 0L, 0);
51*4286Seric 	write(fd, &stat, sizeof stat);
52*4286Seric 	close(fd);
53*4286Seric }
54*4286Seric /*
55*4286Seric **  KBYTES -- given a number, returns the number of Kbytes.
56*4286Seric **
57*4286Seric **	Used in statistics gathering of message sizes to try to avoid
58*4286Seric **	wraparound (at least for a while.....)
59*4286Seric **
60*4286Seric **	Parameters:
61*4286Seric **		bytes -- actual number of bytes.
62*4286Seric **
63*4286Seric **	Returns:
64*4286Seric **		number of kbytes.
65*4286Seric **
66*4286Seric **	Side Effects:
67*4286Seric **		none.
68*4286Seric **
69*4286Seric **	Notes:
70*4286Seric **		This function is actually a ceiling function to
71*4286Seric **			the nearest K.
72*4286Seric **		Honestly folks, floating point might be better.
73*4286Seric **			Or perhaps a "statistical" log method.
74*4286Seric */
75*4286Seric 
76*4286Seric long
77*4286Seric kbytes(bytes)
78*4286Seric 	long bytes;
79*4286Seric {
80*4286Seric 	return ((bytes + 999) / 1000);
81*4286Seric }
82