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

📄 gnxseq.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic char sccsid[] = "@(#)gnxseq.c	4.1 (decvax!larry) 7/2/90";#endif#include "uucp.h"#include <sys/types.h>#include <sys/time.h>extern	time_t	time();/******* *	gnxseq(rmtname)		get next conversation sequence number *	char *rmtname; * *	return - 0 no entry | >0 sequence number ********//********* *  Mods:  *	decvax!larry - return immediately if SQFILE does not exist. * *********//************************************************************************ *									* *			Copyright (c) 1984 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/gnxseq(rmtname)char *rmtname;{	int count = 0, ct, ret, i;	struct tm *tp;	extern struct tm *localtime();	time_t clock;	FILE *fp0, *fp1;	char buf[BUFSIZ], name[NAMESIZE];	if ((fp0 = fopen(SQFILE, "r")) == NULL)		return(0);	if ((fp1 = fopen(SQTMP, "w")) == NULL) {		fclose(fp0);		return(0);	}	for (i = 0; i < 5; i++) {		if ((ret = ulockf(SQLOCK, (time_t)  SQTIME)) == 0)			break;		sleep(5);	}	if (ret != 0) {		logent("CAN'T LOCK", SQLOCK);		DEBUG(4, "can't lock %s\n", SQLOCK);		fclose(fp0);		fclose(fp1);		return(0);	}	chmod(SQTMP, 0400);	while (fgets(buf, BUFSIZ, fp0) != NULL) {		ret = sscanf(buf, "%s%d", name, &ct);		if (ret < 2)			ct = 0;		name[7] = '\0';		if (ct > 9998)			ct = 0;		if (strcmp(rmtname, name) != SAME) {			fputs(buf, fp1);			continue;		}		/*  found name  */		count = ++ct;		time(&clock);		tp = localtime(&clock);		fprintf(fp1, "%s %d %d/%d-%d:%02d\n", name, ct,		  tp->tm_mon + 1, tp->tm_mday, tp->tm_hour,		  tp->tm_min);		while (fgets(buf, BUFSIZ, fp0) != NULL)			fputs(buf, fp1);	}	fclose(fp0);	fclose(fp1);	if (count == 0) {		rmlock(SQLOCK);		unlink(SQTMP);	}	return(count);}/*** *	cmtseq()	commit sequence update * *	return  0  ok | other - link failed */cmtseq(){	int ret;	if ((ret = access(SQTMP, 4)) != 0) {		rmlock(SQLOCK);		return(0);	}	unlink(SQFILE);	ret = link(SQTMP, SQFILE);	unlink(SQTMP);	rmlock(SQLOCK);	return(ret);}/*** *	ulkseq()	unlock sequence file */ulkseq(){	unlink(SQTMP);	rmlock(SQLOCK);}

⌨️ 快捷键说明

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