home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / c / cbase.zoo / btree101.zoo / btgetk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-20  |  1.8 KB  |  80 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btgetk.c    1.4 - 90/06/20" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /*#include <string.h>*/
  9.  
  10. /* local headers */
  11. #include "btree_.h"
  12.  
  13. /*man---------------------------------------------------------------------------
  14. NAME
  15.      btgetk - read current btree key
  16.  
  17. SYNOPSIS
  18.      #include <btree.h>
  19.  
  20.      int btgetk(btp, buf)
  21.      btree_t *btp;
  22.      void *buf;
  23.  
  24. DESCRIPTION
  25.      The btgetk function reads the key from the current cursor
  26.      position in btree btp into buf.  buf must point to a storage area
  27.      as large as the key size for btp.
  28.  
  29.      btgetk will fail if one or more of the following is true:
  30.  
  31.      [EINVAL]       btp is not a valid btree pointer.
  32.      [EINVAL]       buf is the NULL pointer.
  33.      [BTELOCK]      btp is not read locked.
  34.      [BTENKEY]      The cursor is null.
  35.      [BTENOPEN]     btp is not open.
  36.  
  37. SEE ALSO
  38.      btcursor, btkeysize, btsearch.
  39.  
  40. DIAGNOSTICS
  41.      Upon successful completion, a value of 0 is returned.  Otherwise,
  42.      a value of -1 is returned, and errno set to indicate the error.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. int btgetk(btp, buf)
  46. btree_t *btp;
  47. void *buf;
  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 (btp->cbtpos.node == NIL) {
  72.         errno = BTENKEY;
  73.         return -1;
  74.     }
  75.     memcpy(buf, bt_kykeyp(btp, btp->cbtnp, btp->cbtpos.key), btp->bthdr.keysize);
  76.  
  77.     errno = 0;
  78.     return 0;
  79. }
  80.