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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "cbgetrf.c    1.1 - 89/08/31" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. #include <lseq.h>
  9. #include "cbase_.h"
  10.  
  11. /*man---------------------------------------------------------------------------
  12. NAME
  13.      cbgetrf - get cbase record field
  14.  
  15. SYNOPSIS
  16.      #include <cbase.h>
  17.  
  18.      int cbgetrf(cbp, field, buf)
  19.      cbase_t *cbp;
  20.      int field;
  21.      void *buf;
  22.  
  23. DESCRIPTION
  24.      The cbgetrf function reads a field from the current record of cbase
  25.      cbp into buf.  field is the number of the field to read.  buf must
  26.      point to a storage area as large as the size of the indicated field.
  27.  
  28.      cbgetrf 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.      [CBELOCK]      cbp is not read locked.
  33.      [CBENOPEN]     cbp is not open.
  34.      [CBENREC]      The record cursor for cbp is null.
  35.  
  36. SEE ALSO
  37.      cbcursor, cbgetr, cbputrf.
  38.  
  39. DIAGNOSTICS
  40.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  41.      value of -1 is returned, and errno set to indicate the error.
  42.  
  43. ------------------------------------------------------------------------------*/
  44. int cbgetrf(cbp, field, buf)
  45. cbase_t * cbp;
  46. int       field;
  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 read locked */
  66.     if (!(cbp->flags & CBRDLCK)) {
  67.         errno = CBELOCK;
  68.         return -1;
  69.     }
  70.  
  71.     /* check if cursor is null */
  72.     if (lscursor(cbp->lsp) == NULL) {
  73.         errno = CBENREC;
  74.         return -1;
  75.     }
  76.  
  77.     /* validate field argument */
  78.     if ((field < 1) || (field > cbp->fldcnt)) {
  79.         errno = EINVAL;
  80.         return -1;
  81.     }
  82.  
  83.     /* read field */
  84.     rs = lsgetrf(cbp->lsp, cbp->fields[field - 1].offset, buf,
  85.                         cbp->fields[field - 1].size);
  86.     if (rs == -1) {
  87.         CBEPRINT;
  88.         return -1;
  89.     }
  90.  
  91.     errno = 0;
  92.     return 0;
  93. }
  94.