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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)bclose.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8. /*#include <string.h>*/
  9.  
  10. /* local headers */
  11. #include "blkio_.h"
  12.  
  13. /*man---------------------------------------------------------------------------
  14. NAME
  15.      bclose - close a block file
  16.  
  17. SYNOPSIS
  18.      #include <blkio.h>
  19.  
  20.      int bclose(bp)
  21.      BLKFILE *bp;
  22.  
  23. DESCRIPTION
  24.      The bclose function causes any buffered data for the block file
  25.      associated with BLKFILE pointer bp to be written out, and the
  26.      block file to be closed.
  27.  
  28.      bclose will fail if one or more of the following is true:
  29.  
  30.      [EINVAL]       bp is not a valid BLKFILE pointer.
  31.      [BENOPEN]      bp is not open.
  32.  
  33. SEE ALSO
  34.      bexit, bopen, bsync.
  35.  
  36. DIAGNOSTICS
  37.      Upon successful completion, a value of 0 is returned.  Otherwise,
  38.      a value of -1 is returned, and errno set to indicate the error.
  39.  
  40. ------------------------------------------------------------------------------*/
  41. int bclose(bp)
  42. BLKFILE *bp;
  43. {
  44.     /* validate arguments */
  45.     if (!b_valid(bp)) {
  46.         errno = EINVAL;
  47.         return -1;
  48.     }
  49.  
  50.     /* check if not open */
  51.     if (!(bp->flags & BIOOPEN)) {
  52.         errno = BENOPEN;
  53.         return -1;
  54.     }
  55.  
  56.     /* synchronize file with buffers */
  57.     if (bsync(bp) == -1) {
  58.         BEPRINT;
  59.         return -1;
  60.     }
  61.  
  62.     /* close file */
  63.     if (b_uclose(bp) == -1) {
  64.         BEPRINT;
  65.         return -1;
  66.     }
  67.  
  68.     /* free memory allocated for block file */
  69.     b_free(bp);
  70.  
  71.     /* scrub slot in biob table then free it */
  72.     memset(bp, 0, sizeof(*biob));
  73.     bp->flags = 0;
  74.  
  75.     errno = 0;
  76.     return 0;
  77. }
  78.