putline.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 141 行
C
141 行
#ifndef lintstatic char *sccsid = "@(#)putline.c 4.1 (ULTRIX) 7/17/90";#endif lint/************************************************************************ * * * Copyright (c) 1988 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. * * * ************************************************************************//* * Modification history * * 29 Jun 88 -- D. Long * Don't use return value from fputs, Ultrix is not SVID * compliant here and returns undefined. Use ferror instead. * Also do error checking on fprintf's and fclose's. * 1 Aug 88 -- D. Long * Fix previous fix. Don't do a FAILPUT in xrm. */# include "../hdr/defines.h"/* Routine to write out either the current line in the packet (if newline is zero) or the line specified by newline. A line is actually written (and the x-file is only opened) if pkt->p_upd is non-zero. When the current line from the packet is written, pkt->p_wrttn is set non-zero, and further attempts to write it are ignored. When a line is read into the packet, pkt->p_wrttn must be turned off.*/int Xcreate;FILE *Xiop;putline(pkt,newline)register struct packet *pkt;char *newline;{ char *xf, *auxf(); register char *p; FILE *fdfopen(); if(pkt->p_upd == 0) return; if(!Xcreate) { stat(pkt->p_file,&Statbuf); xf = auxf(pkt->p_file,'x'); Xiop = xfcreat(xf,Statbuf.st_mode); chown(xf,Statbuf.st_uid,Statbuf.st_gid); } if (newline) p = newline; else { if(!pkt->p_wrttn++) p = pkt->p_line; else p = 0; } if (p) { fputs(p,Xiop); if(ferror(Xiop)) FAILPUT; if (Xcreate) while (*p) pkt->p_nhash += *p++; } Xcreate = 1;}flushline(pkt,stats)register struct packet *pkt;register struct stats *stats;{ register char *p; char ins[6], del[6], unc[6], hash[6]; if (pkt->p_upd == 0) return; putline(pkt,(char *) 0); if(fseek(Xiop, 0L, 0)) FAILPUT; if (stats) { sprintf(ins,"%.05u",stats->s_ins); sprintf(del,"%.05u",stats->s_del); sprintf(unc,"%.05u",stats->s_unc); for (p = ins; *p; p++) pkt->p_nhash += (*p - '0'); for (p = del; *p; p++) pkt->p_nhash += (*p - '0'); for (p = unc; *p; p++) pkt->p_nhash += (*p - '0'); } sprintf(hash,"%5u",pkt->p_nhash&0xFFFF); zeropad(hash); if(fprintf(Xiop,"%c%c%s\n",CTLCHAR,HEAD,hash)==EOF) FAILPUT; if (stats) if(fprintf(Xiop,"%c%c %s/%s/%s\n",CTLCHAR,STATS,ins,del,unc)==EOF) FAILPUT; if(fclose(Xiop)==EOF) FAILPUT;}xrm(pkt)struct packet *pkt;{ if (Xiop) fclose(Xiop); Xiop = 0; Xcreate = 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?