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

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