bclose.cpp

来自「CBASE v1.01 采用Borland公司TC++编写的数据库管理源程序库」· C++ 代码 · 共 77 行

CPP
77
字号
/*	Copyright (c) 1989 Citadel	*/
/*	   All Rights Reserved    	*/

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

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

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

/*man---------------------------------------------------------------------------
NAME
     bclose - close a block file

SYNOPSIS
     #include <blkio.h>

     int bclose(bp)
     BLKFILE *bp;

DESCRIPTION
     The bclose function causes any buffered data for the block file
     associated with BLKFILE pointer bp to be written out, and the
     block file to be closed.

     bclose 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, bopen, bsync.

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 bclose(BLKFILE *bp)
{
	/* validate arguments */
	if (!b_valid(bp)) {
		errno = EINVAL;
		return -1;
	}

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

	/* synchronize file with buffers */
	if (bsync(bp) == -1) {
		BEPRINT;
		return -1;
	}

	/* close file */
	if (b_uclose(bp) == -1) {
		BEPRINT;
		return -1;
	}

	/* free memory allocated for block file */
	b_free(bp);

	/* scrub slot in biob table then free it */
	memset(bp, 0, sizeof(*biob));
	bp->flags = 0;

	errno = 0;
	return 0;
}

⌨️ 快捷键说明

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