home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CBASE101.ZIP / BLKIO112.ZIP / BSETBUF.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  77 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)bsetbuf.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8. /*#include <stddef.h>*/
  9.  
  10. /* local headers */
  11. #include "blkio_.h"
  12.  
  13. /*man---------------------------------------------------------------------------
  14. NAME
  15.      bsetbuf - assign buffering to a block file
  16.  
  17. SYNOPSIS
  18.      #include <blkio.h>
  19.  
  20.      int bsetbuf(bp, buf)
  21.      BLKFILE *bp;
  22.      void *buf;
  23.  
  24. DESCRIPTION
  25.      The bsetbuf function causes the storage area pointed to by buf to
  26.      be used by the block file associated with BLKFILE pointer bp
  27.      instead of an automatically allocated buffer area.  If buf is the
  28.      NULL pointer, bp will be completely unbuffered.  Otherwise, it
  29.      must point to a storage area of size no less than
  30.  
  31.           header size + block size * buffer count
  32.  
  33.      bsetbuf may be called at any time after opening the block file,
  34.      before and after it is read or written; the buffers are flushed
  35.      before installing the new buffer area.
  36.  
  37.      bsetbuf will fail if one or more of the following is true:
  38.  
  39.      [EINVAL]       bp is not a valid BLKFILE pointer.
  40.      [BENBUF]       bp is unbuffered and buf is not the NULL
  41.                     pointer.
  42.      [BENOPEN]      bp is not open.
  43.  
  44. SEE ALSO
  45.      bopen, bsetvbuf.
  46.  
  47. DIAGNOSTICS
  48.      Upon successful completion, a value of 0 is returned.  Otherwise,
  49.      a value of -1 is returned, and errno set to indicate the error.
  50.  
  51. NOTES
  52.      A common source of error is allocating buffer space as an
  53.      automatic variable in a code block, and then failing to close the
  54.      block file in the same block.
  55.  
  56. ------------------------------------------------------------------------------*/
  57. int bsetbuf(bp, buf)
  58. BLKFILE *bp;
  59. void *buf;
  60. {
  61.     /* validate arguments */
  62.     if (!b_valid(bp)) {
  63.         errno = EINVAL;
  64.         return -1;
  65.     }
  66.     if ((bp->bufcnt == 0) && (buf != NULL)) {
  67.         errno = BENBUF;
  68.         return -1;
  69.     }
  70.  
  71.     if (buf == NULL) {
  72.         return bsetvbuf(bp, buf, bp->blksize, (size_t)0);
  73.     }
  74.  
  75.     return bsetvbuf(bp, buf, bp->blksize, bp->bufcnt);
  76. }
  77.