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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "btgetk.c    1.1 - 89/07/03" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /* #include <string.h> */
  9. #include "btree_.h"
  10.  
  11. /*man---------------------------------------------------------------------------
  12. NAME
  13.      btgetk - read current btree key
  14.  
  15. SYNOPSIS
  16.      #include <btree.h>
  17.  
  18.      int btgetk(btp, buf)
  19.      btree_t *btp;
  20.      void *buf;
  21.  
  22. DESCRIPTION
  23.      The btgetk function reads the key from the current cursor position
  24.      in btree btp into buf.  buf must point to a storage area as large as
  25.      the key size for btp.
  26.  
  27.      btgetk will fail if one or more of the following is true:
  28.  
  29.      [EINVAL]       btp is not a valid btree pointer.
  30.      [EINVAL]       buf is the NULL pointer.
  31.      [BTELOCK]      btp is not read locked.
  32.      [BTENKEY]      The cursor is null.
  33.      [BTENOPEN]     btp is not open.
  34.  
  35. SEE ALSO
  36.      btcursor, btsearch.
  37.  
  38. DIAGNOSTICS
  39.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  40.      value of -1 is returned, and errno set to indicate the error.
  41.  
  42. ------------------------------------------------------------------------------*/
  43. int btgetk(btp, buf)
  44. btree_t * btp;
  45. void *    buf;
  46. {
  47.     errno = 0;
  48.  
  49.     /* validate arguments */
  50.     if ((!bt_valid(btp)) || (buf == NULL)) {
  51.         errno = EINVAL;
  52.         return -1;
  53.     }
  54.  
  55.     /* check if not open */
  56.     if (!(btp->flags & BTOPEN)) {
  57.         errno = EINVAL;
  58.         return -1;
  59.     }
  60.  
  61.     /* check locks */
  62.     if (!(btp->flags & BTRDLCK)) {
  63.         errno = BTELOCK;
  64.         return -1;
  65.     }
  66.  
  67.     /* initialize return value */
  68.     memset(buf, 0, btp->bthdr.keysize);
  69.  
  70.     /* read key value */
  71.     if (btcursor(btp) == NULL) {
  72.         errno = BTENKEY;
  73.         return -1;
  74.     }
  75.     memcpy(buf, bt_kykey_p(btp, btp->cbtnp, btp->cbtpos.key), btp->bthdr.keysize);
  76.  
  77.     errno = 0;
  78.     return 0;
  79. }
  80.