home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / CBASE11.ZIP / LSLAST.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  2KB  |  98 lines

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