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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "lsinsert.c    1.1 - 89/07/03" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /* #include <string.h> */
  9. #include "lseq_.h"
  10.  
  11. /*man---------------------------------------------------------------------------
  12. NAME
  13.      lsinsert - lseq insert
  14.  
  15. SYNOPSIS
  16.      #include <lseq.h>
  17.  
  18.      int lsinsert(lsp, buf)
  19.      lseq_t *lsp;
  20.      void *buf;
  21.  
  22. DESCRIPTION
  23.      The lsinsert function inserts the record pointed to by buf into lseq
  24.      lsp.  The record is inserted as the last record.  The cursor is set to
  25.      the inserted record.
  26.  
  27.      lsinsert will fail if one or more of the following is true:
  28.  
  29.      [EINVAL]       lsp is not a valid lseq pointer.
  30.      [EINVAL]       buf is the NULL pointer.
  31.      [LSELOCK]      lsp is not write locked.
  32.      [LSENOPEN]     lsp is not open.
  33.  
  34. SEE ALSO
  35.      lsdelcur, lsinscur, lssearch.
  36.  
  37. DIAGNOSTICS
  38.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  39.      value of -1 is returned and errno is set to indicate the error.
  40.  
  41. ------------------------------------------------------------------------------*/
  42. int lsinsert(lsp, buf)
  43. lseq_t * lsp;
  44. void *   buf;
  45. {
  46.     int rs = 0;
  47.  
  48.     errno = 0;
  49.  
  50.     /* validate arguments */
  51.     if ((!ls_valid(lsp)) || (buf == NULL)) {
  52.         errno = EINVAL;
  53.         return -1;
  54.     }
  55.  
  56.     /* check if not open */
  57.     if (!(lsp->flags & LSOPEN)) {
  58.         errno = LSENOPEN;
  59.         return -1;
  60.     }
  61.  
  62.     /* check if not write locked */
  63.     if (!(lsp->flags & LSWRLCK)) {
  64.         errno = LSELOCK;
  65.         return -1;
  66.     }
  67.  
  68.     /* set cursor to last record */
  69.     rs = lslast(lsp);
  70.     if (rs == -1) {
  71.         LSEPRINT;
  72.         return -1;
  73.     }
  74.  
  75.     /* insert record */
  76.     rs = lsinscur(lsp, buf);
  77.     if (rs == -1) {
  78.         LSEPRINT;
  79.         return -1;
  80.     }
  81.  
  82.     errno = 0;
  83.     return 0;
  84. }
  85.