home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CBASE09.ZIP / BLKIO10.ZIP / BSETBUF.C < prev    next >
Text File  |  1989-08-30  |  2KB  |  61 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "bsetbuf.c    1.1 - 89/07/03" */
  5.  
  6. #include <errno.h>
  7. #include "blkio_.h"
  8.  
  9. /*man---------------------------------------------------------------------------
  10. NAME
  11.      bsetbuf - assign buffering to a block file
  12.  
  13. SYNOPSIS
  14.      #include <blkio.h>
  15.  
  16.      int bsetbuf(bp, buf)
  17.      BLKFILE *bp;
  18.      void *buf;
  19.  
  20. DESCRIPTION
  21.      The bsetbuf function causes the storage area pointed to by buf to be
  22.      used by the block file associated with BLKFILE pointer bp instead of an
  23.      automatically allocated buffer area.  If buf is the NULL pointer, bp
  24.      will be completely unbuffered.  Otherwise, it must point to a storage
  25.      area of size (header size + buffer count * block size).
  26.  
  27.      bsetbuf may be called at any time after opening the block file, before
  28.      and after it is read or written.
  29.  
  30.      bsetbuf will fail if one or more of the following is true:
  31.  
  32.      [EINVAL]       bp is not a valid BLKFILE pointer.
  33.      [BENBUF]       buf is not the NULL pointer and bp is not
  34.                     buffered.
  35.      [BENOPEN]      bp is not open.
  36.  
  37. SEE ALSO
  38.      bopen, bsetvbuf.
  39.  
  40. DIAGNOSTICS
  41.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  42.      non-zero value is returned, and errno set to indicate the error.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. int bsetbuf(bp, buf)
  46. BLKFILE * bp;
  47. void *    buf;
  48. {
  49.     /* validate arguments */
  50.     if ((bp->bufcnt == 0) && (buf != NULL)) {
  51.         errno = BENBUF;
  52.         return -1;
  53.     }
  54.  
  55.     if (buf == NULL) {
  56.         return bsetvbuf(bp, buf, bp->blksize, (size_t)0);
  57.     }
  58.  
  59.     return bsetvbuf(bp, buf, bp->blksize, bp->bufcnt);
  60. }
  61.