home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / cbase.zip / CBASE10B.ZIP / CBASE.ZIP / CBSYNC.C < prev    next >
Text File  |  1989-11-08  |  2KB  |  75 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "cbsync.c    1.2 - 89/11/08" */
  5.  
  6. #include <btree.h>
  7. #include <errno.h>
  8. #include <lseq.h>
  9. #include "cbase_.h"
  10.  
  11. /*man---------------------------------------------------------------------------
  12. NAME
  13.      cbsync - synchronize cbase
  14.  
  15. SYNOPSIS
  16.      #include <cbase.h>
  17.  
  18.      int cbsync(cbp)
  19.      cbase_t *cbp;
  20.  
  21. DESCRIPTION
  22.      The cbsync function causes any buffered data for the named cbase
  23.      to be written out, both for the record and the key files.  The
  24.      cbase remains open and the buffer contents remain intact.
  25.  
  26.      cbsync will fail if one or more of the following is true:
  27.  
  28.      [EINVAL]       cbp is not a valid cbase pointer.
  29.      [EINVAL]       cbp is not open.
  30.  
  31. SEE ALSO
  32.      cbclose, cblock.
  33.  
  34. DIAGNOSTICS
  35.      Upon successful completion, a value of 0 is returned.  Otherwise,
  36.      a value of -1 is returned, and errno set to indicate the error.
  37.  
  38. ------------------------------------------------------------------------------*/
  39. int cbsync(cbp)
  40. cbase_t *cbp;
  41. {
  42.     int i = 0;
  43.  
  44.     /* validate input parameters */
  45.     if (!cb_valid(cbp)) {
  46.         errno = EINVAL;
  47.         return -1;
  48.     }
  49.  
  50.     /* check if not open */
  51.     if (!(cbp->flags & CBOPEN)) {
  52.         errno = CBENOPEN;
  53.         return -1;
  54.     }
  55.  
  56.     /* synchronize record file with buffers */
  57.     if (lssync(cbp->lsp) == -1) {
  58.         CBEPRINT;
  59.         return -1;
  60.     }
  61.  
  62.     /* synchronize key files with buffers */
  63.     for (i = 0; i < cbp->fldc; i++) {
  64.         if (cbp->fldv[i].flags & CB_FKEY) {
  65.             if (btsync(cbp->btpv[i]) == -1) {
  66.                 CBEPRINT;
  67.                 return -1;
  68.             }
  69.         }
  70.     }
  71.  
  72.     errno = 0;
  73.     return 0;
  74. }
  75.