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

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