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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "cbreclas.c    1.1 - 89/08/31" */
  5.  
  6. #include <errno.h>
  7. #include <lseq.h>
  8. #include "cbase_.h"
  9.  
  10. /*man---------------------------------------------------------------------------
  11. NAME
  12.      cbreclast - last cbase record
  13.  
  14. SYNOPSIS
  15.      #include <cbase.h>
  16.  
  17.      int cbreclast(cbp)
  18.      cbase_t *cbp;
  19.  
  20. DESCRIPTION
  21.      The cbreclast function positions the record cursor of cbase cbp to
  22.      the last record.
  23.  
  24.      cbreclast will fail if one or more of the following is true:
  25.  
  26.      [EINVAL]       cbp is not a valid cbase pointer.
  27.      [CBELOCK]      cbp is not locked.
  28.      [CBENOPEN]     cbp is not open.
  29.      [CBENREC]      cbp is empty.
  30.  
  31. SEE ALSO
  32.      cbreccnt, cbrecfirst, cbrecnext, cbrecprev.
  33.  
  34. DIAGNOSTICS
  35.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  36.      value of -1 is returned, and errno set to indicate the error.
  37.  
  38. ------------------------------------------------------------------------------*/
  39. int cbreclast(cbp)
  40. cbase_t *cbp;
  41. {
  42.     int rs = 0;
  43.  
  44.     errno = 0;
  45.  
  46.     /* validate arguments */
  47.     if (!cb_valid(cbp)) {
  48.         errno = EINVAL;
  49.         return -1;
  50.     }
  51.  
  52.     /* check if not open */
  53.     if (!(cbp->flags & CBOPEN)) {
  54.         errno = CBENOPEN;
  55.         return -1;
  56.     }
  57.  
  58.     /* check if not locked */
  59.     if (!(cbp->flags & CBLOCKS)) {
  60.         errno = CBELOCK;
  61.         return -1;
  62.     }
  63.  
  64.     /* check if cbp is empty */
  65.     if (lsreccnt(cbp->lsp) == 0) {
  66.         errno = CBENREC;
  67.         return -1;
  68.     }
  69.  
  70.     /* set cursor to last record */
  71.     rs = lslast(cbp->lsp);
  72.     if (rs == -1) {
  73.         CBEPRINT;
  74.         return -1;
  75.     }
  76.  
  77.     errno = 0;
  78.     return 0;
  79. }
  80.