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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "cbinsert.c    1.1 - 89/08/31" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. #include <lseq.h>
  9. /* #include <string.h> */
  10. #include "cbase_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      cbinsert - cbase insert
  15.  
  16. SYNOPSIS
  17.      #include <cbase.h>
  18.  
  19.      int cbinsert(cbp, buf)
  20.      cbase_t *cbp;
  21.      void *buf;
  22.  
  23. DESCRIPTION
  24.      The cbinsert function inserts the record pointed to by buf into cbase
  25.      cbp.  The record is inserted as the last record.  The record cursor
  26.      and all key cursors are set to the inserted record.
  27.  
  28.      cbinsert will fail if one or more of the following is true:
  29.  
  30.      [EINVAL]       cbp is not a valid cbase pointer.
  31.      [EINVAL]       buf is the NULL pointer.
  32.      [CBEDUP]       A field in the record pointed to by
  33.                     buf contains an illegal duplicate key.
  34.      [CBELOCK]      cbp is not write locked.
  35.      [CBENOPEN]     cbp is not open.
  36.  
  37. SEE ACBO
  38.      cbdelcur, cbinscur.
  39.  
  40. DIAGNOSTICS
  41.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  42.      value of -1 is returned and errno is set to indicate the error.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. int cbinsert(cbp, buf)
  46. cbase_t * cbp;
  47. void *    buf;
  48. {
  49.     int rs = 0;
  50.  
  51.     errno = 0;
  52.  
  53.     /* validate arguments */
  54.     if ((!cb_valid(cbp)) || (buf == NULL)) {
  55.         errno = EINVAL;
  56.         return -1;
  57.     }
  58.  
  59.     /* check if not open */
  60.     if (!(cbp->flags & CBOPEN)) {
  61.         errno = CBENOPEN;
  62.         return -1;
  63.     }
  64.  
  65.     /* check if not write locked */
  66.     if (!(cbp->flags & CBWRLCK)) {
  67.         errno = CBELOCK;
  68.         return -1;
  69.     }
  70.  
  71.     /* set record cursor to last record */
  72.     if (lsreccnt(cbp->lsp) != 0) {
  73.         rs = lslast(cbp->lsp);
  74.         if (rs == -1) {
  75.             CBEPRINT;
  76.             return -1;
  77.         }
  78.     }
  79.  
  80.     /* insert new record */
  81.     rs = cbinscur(cbp, buf);
  82.     if (rs == -1) {
  83.         return -1;
  84.     }
  85.  
  86.     errno = 0;
  87.     return 0;
  88. }
  89.