14286Seric # include "sendmail.h"
24286Seric 
3*4319Seric static char	SccsId[] =	"@(#)stats.c	3.2	09/06/81";
44286Seric 
54286Seric /*
64286Seric **  POSTSTATS -- post statistics in the statistics file
74286Seric **
84286Seric **	Parameters:
94286Seric **		sfile -- the name of the statistics file.
104286Seric **
114286Seric **	Returns:
124286Seric **		none.
134286Seric **
144286Seric **	Side Effects:
154286Seric **		merges the Stat structure with the sfile file.
164286Seric */
174286Seric 
184286Seric struct statistics	Stat;
194286Seric 
204286Seric poststats(sfile)
214286Seric 	char *sfile;
224286Seric {
234286Seric 	register int fd;
244286Seric 	struct statistics stat;
25*4319Seric 	extern long lseek();
26*4319Seric 	extern long time();
274286Seric 
28*4319Seric 	(void) time(&Stat.stat_itime);
294286Seric 	Stat.stat_size = sizeof Stat;
304286Seric 
314286Seric 	fd = open(sfile, 2);
324286Seric 	if (fd < 0)
334286Seric 		return;
34*4319Seric 	if (read(fd, (char *) &stat, sizeof stat) == sizeof stat &&
354286Seric 	    stat.stat_size == sizeof stat)
364286Seric 	{
374286Seric 		/* merge current statistics into statfile */
384286Seric 		register int i;
394286Seric 
404286Seric 		for (i = 0; i < MAXMAILERS; i++)
414286Seric 		{
424286Seric 			stat.stat_nf[i] += Stat.stat_nf[i];
434286Seric 			stat.stat_bf[i] += Stat.stat_bf[i];
444286Seric 			stat.stat_nt[i] += Stat.stat_nt[i];
454286Seric 			stat.stat_bt[i] += Stat.stat_bt[i];
464286Seric 		}
474286Seric 	}
484286Seric 	else
49*4319Seric 		bmove((char *) &Stat, (char *) &stat, sizeof stat);
504286Seric 
514286Seric 	/* write out results */
52*4319Seric 	(void) lseek(fd, 0L, 0);
53*4319Seric 	(void) write(fd, (char *) &stat, sizeof stat);
54*4319Seric 	(void) close(fd);
554286Seric }
564286Seric /*
574286Seric **  KBYTES -- given a number, returns the number of Kbytes.
584286Seric **
594286Seric **	Used in statistics gathering of message sizes to try to avoid
604286Seric **	wraparound (at least for a while.....)
614286Seric **
624286Seric **	Parameters:
634286Seric **		bytes -- actual number of bytes.
644286Seric **
654286Seric **	Returns:
664286Seric **		number of kbytes.
674286Seric **
684286Seric **	Side Effects:
694286Seric **		none.
704286Seric **
714286Seric **	Notes:
724286Seric **		This function is actually a ceiling function to
734286Seric **			the nearest K.
744286Seric **		Honestly folks, floating point might be better.
754286Seric **			Or perhaps a "statistical" log method.
764286Seric */
774286Seric 
784286Seric long
794286Seric kbytes(bytes)
804286Seric 	long bytes;
814286Seric {
824286Seric 	return ((bytes + 999) / 1000);
834286Seric }
84