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

📄 writeidx.c

📁 用C语言编的邮件系统(毕业论文)
💻 C
字号:
#include	"mail.h"#include	<sys/uio.h>		/* struct iovec *//* Write an index record. * _mail_writedat() is called before this function, to set the fields * datoff and datlen in the mail structure, which we need to write * the index record. */void_mail_writeidx(MAIL *mail,struct message *msg,					 off_t offset, int whence, off_t ptrval){	struct iovec	iov[2];	char		asciiptrlen[PTR_SZ + IDXLEN_SZ +1];	int		len;	if ( (mail->ptrval = ptrval) < 0 || ptrval > PTR_MAX)		err_quit("invalid ptr: %d", ptrval);        if(msg!=NULL)         {	 sprintf(mail->idxbuf, "%s%c%s%c%d%c%d\n",		msg->messageid, SEP,hint,SEP, mail->datoff, SEP, mail->datlen);                    len=strlen(mail->idxbuf);          }         else len=mail->idxlen;    	if ( len < IDXLEN_MIN || len > IDXLEN_MAX)		err_dump("invalid length");	sprintf(asciiptrlen, "%*d%*d", PTR_SZ, ptrval, IDXLEN_SZ, len);		/* If we're appending, we have to lock before doing the lseek()		   and write() to make the two an atomic operation.  If we're		   overwriting an existing record, we don't have to lock. */	if (whence == SEEK_END)		/* we're appending */		if (writew_lock(mail->idxfd, ((mail->nhash+1)*PTR_SZ)+1,													SEEK_SET, 0) < 0)			err_dump("writew_lock error");		/* Position the index file and record the offset */	if ( (mail->idxoff = lseek(mail->idxfd, offset, whence)) == -1)		err_dump("lseek error");	iov[0].iov_base = asciiptrlen;	iov[0].iov_len  = PTR_SZ + IDXLEN_SZ;                                   	iov[1].iov_base = mail->idxbuf;	iov[1].iov_len  = strlen(mail->idxbuf);	if (writev(mail->idxfd, &iov[0], 2) != PTR_SZ + IDXLEN_SZ + strlen(mail->idxbuf))		err_dump("writev error of index record");	if (whence == SEEK_END)		if (un_lock(mail->idxfd, ((mail->nhash+1)*PTR_SZ)+1, SEEK_SET, 0) < 0)			err_dump("un_lock error");}

⌨️ 快捷键说明

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