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