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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "cbrecpre.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.      cbrecprev - previous cbase record
  13.  
  14. SYNOPSIS
  15.      #include <cbase.h>
  16.  
  17.      int cbrecprev(cbp)
  18.      cbase_t *cbp;
  19.  
  20. DESCRIPTION
  21.      The cbrecprev function retreats the record cursor of cbase cbp to
  22.      the previous record.  If the cursor is on the first record, it is
  23.      retreated to null.
  24.  
  25.      cbrecprev will fail if one or more of the following is true:
  26.  
  27.      [EINVAL]       cbp is not a valid cbase pointer.
  28.      [CBELOCK]      cbp is not locked.
  29.      [CBENOPEN]     cbp is not open.
  30.  
  31. SEE ALSO
  32.      cbrcursor, cbrecfirst, cbreclast, cbrecnext.
  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 cbrecprev(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.     /* retreat cursor to previous record */
  65.     rs = lsprev(cbp->lsp);
  66.     if (rs == -1) {
  67.         CBEPRINT;
  68.         return -1;
  69.     }
  70.  
  71.     errno = 0;
  72.     return 0;
  73. }
  74.