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

📄 dodelete.c

📁 APUE(第二版)的随书源代码,与第一版的代码相比增加了一些章节的代码(详见第二版的说明)
💻 C
字号:
#include	"db.h"/* Delete the current record specified by the DB structure. * This function is called by db_delete() and db_store(), * after the record has been located by _db_find(). */int_db_dodelete(DB *db){	int		i;	char	*ptr;	off_t	freeptr, saveptr;		/* Set data buffer to all blanks */	for (ptr = db->datbuf, i = 0; i < db->datlen - 1; i++)		*ptr++ = ' ';	*ptr = 0;	/* null terminate for _db_writedat() */		/* Set key to blanks */	ptr = db->idxbuf;	while (*ptr)		*ptr++ = ' ';		/* We have to lock the free list */	if (writew_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)		err_dump("writew_lock error");		/* Write the data record with all blanks */	_db_writedat(db, db->datbuf, db->datoff, SEEK_SET);		/* Read the free list pointer.  Its value becomes the		   chain ptr field of the deleted index record.  This means		   the deleted record becomes the head of the free list. */	freeptr = _db_readptr(db, FREE_OFF);		/* Save the contents of index record chain ptr,		   before it's rewritten by _db_writeidx(). */	saveptr = db->ptrval;		/* Rewrite the index record.  This also rewrites the length		   of the index record, the data offset, and the data length,		   none of which has changed, but that's OK. */	_db_writeidx(db, db->idxbuf, db->idxoff, SEEK_SET, freeptr);		/* Write the new free list pointer */	_db_writeptr(db, FREE_OFF, db->idxoff);		/* Rewrite the chain ptr that pointed to this record		   being deleted.  Recall that _db_find() sets db->ptroff		   to point to this chain ptr.  We set this chain ptr		   to the contents of the deleted record's chain ptr,		   saveptr, which can be either zero or nonzero. */	_db_writeptr(db, db->ptroff, saveptr);	if (un_lock(db->idxfd, FREE_OFF, SEEK_SET, 1) < 0)		err_dump("un_lock error");	return(0);}

⌨️ 快捷键说明

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