home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / c / cbase.zoo / lseq101.zoo / lsclose.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-20  |  1.7 KB  |  80 lines

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