cbrecali.cpp
来自「CBASE v1.01 采用Borland公司TC++编写的数据库管理源程序库」· C++ 代码 · 共 135 行
CPP
135 行
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "@(#)cbrecali.c 1.4 - 90/06/20" */
/* ansi headers */
#include <errno.h>
/*#include <stdlib.h>*/
/*#include <string.h>*/
/* library headers */
#include "blkio.h"
#include "btree.h"
#include "lseq.h"
/* local headers */
#include "cbase_.h"
/*man---------------------------------------------------------------------------
NAME
cbrecalign - align cbase record cursor
SYNOPSIS
#include <cbase.h>
int cbrecalign(cbp, field)
cbase_t *cbp;
int field;
DESCRIPTION
The cbrecalign function aligns the record cursor in cbase cbp
with the key cursor for the specified field. Other cursors are
not affected.
cbrecalign will fail if one or more of the following is true:
[EINVAL] cbp is not a valid cbase pointer.
[EINVAL] field is not a valid field number for
cbase cbp.
[CBELOCK] cbp is not locked.
[CBENKEY] field is not a key.
[CBENOPEN] cbp is not open.
SEE ALSO
cbkeyalign, cbrecfirst, cbreclast, cbrecnext, cbrecprev.
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 cbrecalign(cbase_t *cbp, int field)
{
void *buf = NULL;
cbrpos_t cbrpos = NIL;
lspos_t lspos = NIL;
/* validate arguments */
if (!cb_valid(cbp)) {
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(cbp->flags & CBOPEN)) {
errno = CBENOPEN;
return -1;
}
/* validate arguments */
if (field < 0 || field >= cbp->fldc) {
errno = EINVAL;
return -1;
}
/* check if field not a key */
if (!(cbp->fldv[field].flags & CB_FKEY)) {
errno = CBENKEY;
return -1;
}
/* check if not locked */
if (!(cbp->flags & CBLOCKS)) {
errno = CBELOCK;
return -1;
}
/* check if record cursor is null */
if (btcursor(cbp->btpv[field]) == NULL) {
/* set record cursor to null */
if (lssetcur(cbp->lsp, NULL) == -1) {
CBEPRINT;
return -1;
}
errno = 0;
return 0;
}
/* allocate storage for key */
if (btkeysize(cbp->btpv[field]) != (cbp->fldv[field].len + sizeof(cbrpos_t))) {
CBEPRINT;
errno = CBEPANIC;
return -1;
}
buf = calloc((size_t)1, btkeysize(cbp->btpv[field]));
if (buf == NULL) {
CBEPRINT;
errno = ENOMEM;
return -1;
}
/* get key */
if (btgetk(cbp->btpv[field], buf) == -1) {
CBEPRINT;
free(buf);
return -1;
}
/* get record position and place in key */
memcpy(&cbrpos, (char *)buf + cbp->fldv[field].len, sizeof(cbrpos));
lspos = cbrpos;
/* position record cursor */
if (lssetcur(cbp->lsp, &lspos) == -1) {
CBEPRINT;
return -1;
}
free(buf);
buf = NULL;
errno = 0;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?