home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
BLKIO10.ZIP
/
BSETVBUF.C
< prev
next >
Wrap
Text File
|
1989-08-30
|
3KB
|
122 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "bsetvbuf.c 1.1 - 89/07/03" */
#include <errno.h>
/* #include <stdlib.h> */
#include "blkio_.h"
/*man---------------------------------------------------------------------------
NAME
bsetvbuf - assign buffering to a block file
SYNOPSIS
#include <blkio.h>
int bsetvbuf(bp, buf, blksize, bufcnt)
BLKFILE *bp;
void *buf;
size_t blksize;
size_t bufcnt;
DESCRIPTION
The bsetvbuf function causes the buffer block count and block size of
the block file associated with BLKFILE pointer bp to be changed to
bufcnt and blksize, with the same effects as if the file had been opened
with these values. If bufcnt has a value of 0, the file will be
completely unbuffered. If buf is not the NULL pointer, it is used as
the buffer area, in which case is must point to a storage area of size
(header size + bufffer count * block size).
bsetvbuf may be called at any time after opening the block file, before
and after it is read or written.
bsetvbuf will fail if one or more of the following is true:
[EINVAL] bp is not a valid BLKFILE pointer.
[EINVAL] blksize is less than 1.
[BENOPEN] bp is not open.
SEE ALSO
bopen, bsetbuf.
DIAGNOSTICS
Upon successful completion, a value of 0 is returned. Otherwise, a
non-zero value is returned, and errno set to indicate the error.
------------------------------------------------------------------------------*/
int bsetvbuf(bp, buf, blksize, bufcnt)
BLKFILE * bp;
void * buf;
size_t blksize;
size_t bufcnt;
{
int rs = 0;
errno = 0;
/* validate arguments */
if ((!b_valid(bp)) || (blksize == 0)) {
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(bp->flags & BIOOPEN)) {
errno = BENOPEN;
return -1;
}
/* synchronize file with buffers */
rs = bsync(bp);
if (rs == -1) {
BEPRINT;
return -1;
}
/* free old buffer storage */
b_free(bp);
/* load main body of buf control structure */
bp->flags &= ~BIOUSRBUF;
bp->blksize = blksize;
bp->bufcnt = bufcnt;
bp->endblk = 0;
bp->most = 0;
bp->least = 0;
rs = b_uendblk(bp, &(bp->endblk));
if (rs == -1) {
if ((errno != BEBOUND) && (errno != BEEOF)) BEPRINT;
return -1;
}
/* check if not buffered */
if (bp->bufcnt == 0) {
errno = 0;
return 0;
}
/* check if user supplied buffer */
if (buf != NULL) {
bp->flags |= BIOUSRBUF;
bp->blkbuf = buf;
}
/* allocate buffer storage */
rs = b_alloc(bp);
if (rs == -1) {
BEPRINT;
return -1;
}
/* initialize */
rs = b_init(bp);
if (rs == -1) {
BEPRINT;
return NULL;
}
errno = 0;
return 0;
}