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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "btgetcur.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.      btgetcur - get btree cursor
  14.  
  15. SYNOPSIS
  16.      #include <btree.h>
  17.  
  18.      int btgetcur(btp, btpos_p)
  19.      btree_t *btp;
  20.      btpos_t *btpos_p;
  21.  
  22. DESCRIPTION
  23.      The btgetcur function gets the current cursor position for btree btp
  24.      and copies it to btpos_p.  A btree position saved with btgetcur can
  25.      be used to reposition to a key using btsetcur.  It is important to
  26.      remember that a btree position saved with btgetcur is not valid after
  27.      an insertion, deletion, or unlock.
  28.  
  29.      btgetcur will fail if one or more of the following is true:
  30.  
  31.      [EINVAL]       btp is not a valid btree pointer.
  32.      [EINVAL]       btpos_p is the NULL pointer.
  33.      [BTELOCK]      btp is not locked.
  34.      [BTENOPEN]     btp is not open.
  35.  
  36. SEE ALSO
  37.      btsetcur.
  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 btgetcur(btp, btpos_p)
  45. btree_t * btp;
  46. btpos_t * btpos_p;
  47. {
  48.     errno = 0;
  49.  
  50.     /* validate arguments */
  51.     if ((!bt_valid(btp)) || (btpos_p == NULL)) {
  52.         errno = EINVAL;
  53.         return -1;
  54.     }
  55.  
  56.     /* check if not open */
  57.     if (!(btp->flags & BTOPEN)) {
  58.         errno = BTENOPEN;
  59.         return -1;
  60.     }
  61.  
  62.     /* check locks */
  63.     if (!(btp->flags & BTLOCKS)) {
  64.         errno = BTELOCK;
  65.         return -1;
  66.     }
  67.  
  68.     /* get current position */
  69.     memcpy((void *)btpos_p, (void *)&btp->cbtpos, sizeof(btp->cbtpos));
  70.  
  71.     errno = 0;
  72.     return 0;
  73. }
  74.