home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
BLKIO10.ZIP
/
BSYNC.C
< prev
next >
Wrap
Text File
|
1989-08-30
|
2KB
|
109 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "bsync.c 1.1 - 89/07/03" */
#include <errno.h>
#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 0 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(bp)
BLKFILE *bp;
{
int rs = 0;
int i = 0;
#ifdef DEBUG
bpos_t endblk = 0;
#endif
errno = 0;
/* 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;
}
/* sync all blocks */
for (i = 1; i <= bp->bufcnt; i++) {
rs = b_put(bp, (size_t)i);
if (rs == -1) {
BEPRINT;
return -1;
}
}
/* sync header */
rs = b_put(bp, (size_t)0);
if (rs == -1) {
BEPRINT;
return -1;
}
#ifdef DEBUG
/* check block count */
rs = b_uendblk(bp, &endblk);
if (rs == -1) {
BEPRINT;
return -1;
}
if (bp->endblk != endblk) {
BEPRINT;
errno = BEPANIC;
return -1;
}
#endif
errno = 0;
return 0;
}