⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stats.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
字号:
/* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and that due credit is given * to the University of California at Berkeley. The name of the University * may not be used to endorse or promote products derived from this * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * *  Sendmail *  Copyright (c) 1983  Eric P. Allman *  Berkeley, California */# include "sendmail.h"# include "mailstats.h"SCCSID(@(#)stats.c 1.1 92/07/30 SMI); /* from UCB 5.9 3/13/88 */struct statistics	Stat;/***  KBYTES -- given a number, returns the number of Kbytes.****	Used in statistics gathering of message sizes to try to avoid**	wraparound (at least for a while.....)****	Notes:**		This function is actually a ceiling function to**			the nearest K.*/#define KBYTES(bytes) (((bytes) + 1023) >> 10);/***  MARKSTATS -- mark statistics*/markstats(e, to)	register ENVELOPE *e;	register ADDRESS *to;{	if (to == NULL)	{		if (e->e_from.q_mailer != NULL)		{			Stat.stat_nf[e->e_from.q_mailer->m_mno]++;			Stat.stat_bf[e->e_from.q_mailer->m_mno] +=				KBYTES(CurEnv->e_msgsize);		}	}	else	{		Stat.stat_nt[to->q_mailer->m_mno]++;		Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize);	}}/***  POSTSTATS -- post statistics in the statistics file****	Parameters:**		sfile -- the name of the statistics file,**			 or a pointer to an empty string if no statistics**			 collection is desired.****	Returns:**		none.****	Side Effects:**		merges the Stat structure with the sfile file.*/poststats(sfile)	char *sfile;{	register int fd;	struct statistics stat;	extern off_t lseek();	int n;	if (sfile == NULL || *sfile == '\0') 		return;	for (n=0; n<MAXMAILERS;n++)	     if (Mailer[n] && Mailer[n]->m_name)		strncpy(Stat.stat_names[n], Mailer[n]->m_name, NAMELEN);	    else		(void) strcpy(Stat.stat_names[n], "");	(void) time(&Stat.stat_itime);	Stat.stat_size = sizeof Stat;	fd = open(sfile, 2);	if (fd < 0)	{		errno = 0;		return;	}	if (read(fd, (char *) &stat, sizeof stat) == sizeof stat &&	    stat.stat_size == sizeof stat)	{		/* merge current statistics into statfile */		register int i;		for (i = 0; i < MAXMAILERS; i++)		{			stat.stat_nf[i] += Stat.stat_nf[i];			stat.stat_bf[i] += Stat.stat_bf[i];			stat.stat_nt[i] += Stat.stat_nt[i];			stat.stat_bt[i] += Stat.stat_bt[i];		}	}	else		bcopy((char *) &Stat, (char *) &stat, sizeof stat);	/* write out results */	(void) lseek(fd, (off_t) 0, 0);	(void) write(fd, (char *) &stat, sizeof stat);	(void) close(fd);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -