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

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