home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
CBASE.ZIP
/
CBDELCUR.C
< prev
next >
Wrap
Text File
|
1989-08-31
|
3KB
|
121 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "cbdelcur.c 1.1 - 89/08/31" */
#include <errno.h>
/* #include <stdlib.h> */
/* #include <string.h> */
#include "cbase_.h"
/*man---------------------------------------------------------------------------
NAME
cbdelcur - delete current cbase record
SYNOPSIS
#include <cbase.h>
int cbdelcur(cbp)
cbase_t *cbp;
DESCRIPTION
The cbdelcur function deletes the current record of cbase cbp. The
record cursor is positioned to the record following the deleted record.
cbdelcur will fail if one or more of the following is true:
[EINVAL] cbp is not a valid cbase pointer.
[CBELOCK] cbp is not write locked.
[CBENOPEN] cbp is not open.
[CBENREC] The record cursor of cbp is null.
SEE ALSO
cbinscur, cbrcursor.
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 cbdelcur(cbp)
cbase_t * cbp;
{
int rs = 0;
lspos_t lspos = 0;
cbrpos_t cbrpos = 0;
void * buf = NULL;
int i = 0;
errno = 0;
/* validate arguments */
if (!cb_valid(cbp)) {
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(cbp->flags & CBOPEN)) {
errno = CBENOPEN;
return -1;
}
/* check if not write locked */
if (!(cbp->flags & CBWRLCK)) {
errno = CBELOCK;
return -1;
}
/* check if record cursor is null */
if (lscursor(cbp->lsp) == NULL) {
errno = CBENREC;
return -1;
}
/* get record position */
rs = lsgetcur(cbp->lsp, &lspos);
if (rs == -1) {
CBEPRINT;
return -1;
}
cbrpos = lspos;
/* delete keys */
for (i = 0; i < cbp->fldcnt; i++) {
if (cbp->fields[i].flags & CBFKEY) {
buf = calloc(1, cbp->fields[i].size + sizeof(cbrpos_t));
if (buf == NULL) {
CBEPRINT;
errno = ENOMEM;
return -1;
}
rs = lsgetrf(cbp->lsp, cbp->fields[i].offset,
buf, cbp->fields[i].size);
if (rs == -1) {
CBEPRINT;
free(buf);
return -1;
}
memcpy((void *)((char *)buf + cbp->fields[i].size),
(void *)&cbrpos, sizeof(cbrpos_t));
rs = btdelete(cbp->btp[i], buf);
if (rs == -1) {
CBEPRINT;
free(buf);
return -1;
}
free(buf);
buf = NULL;
}
}
/* delete current record */
rs = lsdelcur(cbp->lsp);
if (rs == -1) {
CBEPRINT;
return -1;
}
errno = 0;
return 0;
}