log.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 55 行

C
55 行
字号
#ifndef lintstatic char sccsid[] = "@(#)log.c	4.6 (Berkeley) 6/25/83";#endif#include "tip.h"static	FILE *flog = NULL;/* * Log file maintenance routines */logent(group, num, acu, message)	char *group, *num, *acu, *message;{	char *user, *timestamp;	struct passwd *pwd;	long t;	if (flog == NULL)		return;	if (flock(fileno(flog), LOCK_EX) < 0) {		perror("tip: flock");		return;	}	if ((user = getlogin()) == NOSTR)		if ((pwd = getpwuid(getuid())) == NOPWD)			user = "???";		else			user = pwd->pw_name;	t = time(0);	timestamp = ctime(&t);	timestamp[24] = '\0';	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",		user, timestamp, group,#ifdef PRISTINE		"",#else		num,#endif		acu, message);	fflush(flog);	(void) flock(fileno(flog), LOCK_UN);}loginit(){#ifdef ACULOG	flog = fopen(value(LOG), "a");	if (flog == NULL)		fprintf(stderr, "can't open log file\r\n");#endif}

⌨️ 快捷键说明

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