findfree.c

来自「用C语言编的邮件系统(毕业论文)」· C语言 代码 · 共 56 行

C
56
字号
#include	"mail.h"/* Try to find a free index record and accompanying data record * of the correct sizes.  We're only called by mail_store(). */int_mail_findfree(MAIL *mail, int keylen, int datlen){	int		rc;	off_t	offset, nextoffset, saveoffset;		/* Lock the free list */	if (writew_lock(mail->idxfd, FREE_OFF, SEEK_SET, 1) < 0)		err_dump("writew_lock error");		/* Read the free list pointer */	saveoffset = FREE_OFF;	offset = _mail_readptr(mail, saveoffset);	while (offset != 0) {		nextoffset = _mail_readidx(mail, offset,FREEIDX);		if (strlen(mail->idxbuf) == keylen && mail->datlen == datlen)			break;		/* found a match */		saveoffset = offset;		offset = nextoffset;	}	if (offset == 0)		rc = -1;	/* no match found */	else {			/* Found a free record with matching sizes.			   The index record was read in by _mail_readidx() above,			   which sets mail->ptrval.  Also, saveoffset points to			   the chain ptr that pointed to this empty record on			   the free list.  We set this chain ptr to mail->ptrval,			   which removes the empty record from the free list. */		_mail_writeptr(mail, saveoffset, mail->ptrval);		rc = 0;			/* Notice also that _mail_readidx() set both mail->idxoff			   and mail->datoff.  This is used by the caller, mail_store(),			   to write the new index record and data record. */	}			/* Unlock the free list */	if (un_lock(mail->idxfd, FREE_OFF, SEEK_SET, 1) < 0)		err_dump("un_lock error");	return(rc);}

⌨️ 快捷键说明

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