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

📄 bsync.cpp

📁 CBASE v1.01 采用Borland公司TC++编写的数据库管理源程序库
💻 CPP
字号:
/*	Copyright (c) 1989 Citadel	*/
/*	   All Rights Reserved    	*/

/* #ident	"@(#)bsync.c	1.4 - 90/06/20" */

/* ansi headers */
#include <errno.h>
/*#include <stddef.h>*/

/* local headers */
#include "blkio_.h"

/*man---------------------------------------------------------------------------
NAME
     bsync - synchronize a block file

SYNOPSIS
     #include <blkio.h>

     int bsync(bp)
     BLKFILE *bp;

DESCRIPTION
     The bsync function causes the block file associated with BLKFILE
     pointer bp to be synchronized with its buffers; any buffered data
     which has been written to the buffers is written to the file.
     The header, if it has been modified, is written out last.  The
     block file remains open and the buffers retain their contents.
     If bp is open read-only or is not buffered, there will be no data
     to synchronize and bsync will return a value of zero immediately.

     bsync will fail if one or more of the following is true:

     [EINVAL]       bp is not a valid BLKFILE pointer.
     [BENOPEN]      bp is not open.

SEE ALSO
     bexit, bflush, bputb.

DIAGNOSTICS
     Upon successful completion, a value of 0 is returned.  Otherwise,
     a value of -1 is returned, and errno set to indicate the error.

------------------------------------------------------------------------------*/
int bsync(BLKFILE *bp)
{
	int i = 0;	/* loop counter */

	/* validate arguments */
	if (!b_valid(bp)) {
		errno = EINVAL;
		return -1;
	}

	/* check if not open */
	if (!(bp->flags & BIOOPEN)) {
		errno = BENOPEN;
		return -1;
	}

	/* check if not open for writing */
	if (!(bp->flags & BIOWRITE)) {
		errno = 0;
		return 0;
	}

	/* check if not buffered */
	if (bp->bufcnt == 0) {
		errno = 0;
		return 0;
	}

	/* synchronize block in each buffer */
	for (i = 1; i <= bp->bufcnt; ++i) {
		if (b_put(bp, (size_t)i) == -1) {
			BEPRINT;
			return -1;
		}
	}

	/* synchronize header */
	if (b_put(bp, (size_t)0) == -1) {
		BEPRINT;
		return -1;
	}

	errno = 0;
	return 0;
}

⌨️ 快捷键说明

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