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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lslast.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* local headers */
  10. #include "lseq_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      lslast - last lseq record
  15.  
  16. SYNOPSIS
  17.      #include <lseq.h>
  18.  
  19.      int lslast(lsp)
  20.      lseq_t *lsp;
  21.  
  22. DESCRIPTION
  23.      The lslast function positions the cursor of lseq lsp on the last
  24.      record in that lseq.
  25.  
  26.      lslast will fail if one or more of the following is true:
  27.  
  28.      [EINVAL]       lsp is not a valid lseq pointer.
  29.      [LSELOCK]      lsp is not locked.
  30.      [LSENOPEN]     lsp is not open.
  31.      [LSENREC]      lsp is empty.
  32.  
  33. SEE ALSO
  34.      lsfirst, lsnext, lsprev, lsreccnt.
  35.  
  36. DIAGNOSTICS
  37.      Upon successful completion, a value of 0 is returned.  Otherwise,
  38.      a value of -1 is returned, and errno set to indicate the error.
  39.  
  40. ------------------------------------------------------------------------------*/
  41. int lslast(lsp)
  42. lseq_t *lsp;
  43. {
  44.     /* validate arguments */
  45.     if (!ls_valid(lsp)) {
  46.         errno = EINVAL;
  47.         return -1;
  48.     }
  49.  
  50.     /* check if not open */
  51.     if (!(lsp->flags & LSOPEN)) {
  52.         errno = LSENOPEN;
  53.         return -1;
  54.     }
  55.  
  56.     /* check locks */
  57.     if (!(lsp->flags & LSLOCKS)) {
  58.         errno = LSELOCK;
  59.         return -1;
  60.     }
  61.  
  62.     /* check if lsp is empty */
  63.     if (lsp->lshdr.reccnt == NIL) {
  64.         errno = LSENREC;
  65.         return -1;
  66.     }
  67.  
  68.     /* check if already on last record */
  69.     if (lsp->clspos == lsp->lshdr.last) {
  70.         errno = 0;
  71.         return 0;
  72.     }
  73.  
  74.     /* set cursor to last record */
  75.     lsp->clspos = lsp->lshdr.last;
  76.  
  77.     /* read in last record */
  78.     if (lsp->clspos == NIL) {
  79.         LSEPRINT;
  80.         errno = LSEPANIC;
  81.         return -1;
  82.     } else {
  83.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  84.             LSEPRINT;
  85.             return -1;
  86.         }
  87.     }
  88.  
  89.     errno = 0;
  90.     return 0;
  91. }
  92.