home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
cbase.zip
/
CBASE10B.ZIP
/
CBASE.ZIP
/
CBINSERT.C
< prev
next >
Wrap
Text File
|
1989-11-08
|
2KB
|
87 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "cbinsert.c 1.2 - 89/11/08" */
#include <blkio.h>
#include <errno.h>
#include <lseq.h>
#include "cbase_.h"
/*man---------------------------------------------------------------------------
NAME
cbinsert - cbase insert
SYNOPSIS
#include <cbase.h>
int cbinsert(cbp, buf)
cbase_t *cbp;
const void *buf;
DESCRIPTION
The cbinsert function inserts the record pointed to by buf into
cbase cbp. The record is inserted as the last record. The
record cursor and all key cursors are set to the inserted record.
cbinsert will fail if one or more of the following is true:
[EINVAL] cbp is not a valid cbase pointer.
[EINVAL] buf is the NULL pointer.
[CBEDUP] A field in the record pointed to by
buf contains an illegal duplicate key.
[CBELOCK] cbp is not write locked.
[CBENOPEN] cbp is not open.
SEE ACBO
cbdelcur, cbinscur.
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 cbinsert(cbp, buf)
cbase_t *cbp;
CONST void *buf;
{
/* validate arguments */
if (!cb_valid(cbp) || (buf == NULL)) {
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;
}
/* set record cursor to last record */
if (lsreccnt(cbp->lsp) == 0) {
if (lssetcur(cbp->lsp, NULL) == -1) {
CBEPRINT;
return -1;
}
} else {
if (lslast(cbp->lsp) == -1) {
CBEPRINT;
return -1;
}
}
/* insert new record */
if (cbinscur(cbp, buf) == -1) {
return -1;
}
errno = 0;
return 0;
}