home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
BTREE.ZIP
/
BTSETCUR.C
< prev
next >
Wrap
Text File
|
1989-08-31
|
2KB
|
101 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "btsetcur.c 1.1 - 89/07/03" */
#include <blkio.h>
#include <errno.h>
/* #include <string.h> */
#include "btree_.h"
/*man---------------------------------------------------------------------------
NAME
btsetcur - set btree cursor
SYNOPSIS
#include <btree.h>
int btsetcur(btp, btpos_p)
btree_t *btp;
btpos_t *btpos_p;
DESCRIPTION
The btsetcur function sets the current cursor position for btree
btp to the value in btpos_p. btpos_p should point to a cursor
value saved previously with btgetcur. If btpos_p is the NULL pointer,
the cursor is set to null. It is important to remember that a btree
position saved with btgetcur is not valid after an insertion, deletion,
or unlock.
btsetcur will fail if one or more of the following is true:
[EINVAL] btp is not a valid btree pointer.
[BTELOCK] btp is not locked.
[BTENKEY] btpos_p points to an invalid cursor
value.
[BTENOPEN] btp is not open.
SEE ALSO
btgetcur.
DIAGNOSTICS
Upon successful completion, a value of 0 is returned. Otherwise, a
value of -1 is returned, and errno set to indicate the error.
------------------------------------------------------------------------------*/
int btsetcur(btp, btpos_p)
btree_t * btp;
btpos_t * btpos_p;
{
int rs = 0;
errno = 0;
/* validate arguments */
if (!bt_valid(btp)) {
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(btp->flags & BTOPEN)) {
errno = BTENOPEN;
return -1;
}
/* check locks */
if (!(btp->flags & BTLOCKS)) {
errno = BTELOCK;
return -1;
}
/* set new currency */
if (btpos_p == NULL) {
memset((void *)&btp->cbtpos, 0, sizeof(btp->cbtpos));
} else {
memcpy((void *)&btp->cbtpos, (void *)btpos_p, sizeof(btp->cbtpos));
}
/* read in new current node */
if (btp->cbtpos.node == 0) {
bt_ndinit(btp, btp->cbtnp);
} else {
rs = bt_ndget(btp, btp->cbtpos.node, btp->cbtnp);
if (rs == -1) {
BTEPRINT;
if (errno == BEEOF) errno = BTENKEY;
return -1;
}
}
/* check if key number in range */
if (btp->cbtpos.key > btp->cbtnp->n) {
errno = BTENKEY;
bt_ndinit(btp, btp->cbtnp);
return -1;
}
errno = 0;
return 0;
}