home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
LSEQ.ZIP
/
LSDELCUR.C
< prev
next >
Wrap
Text File
|
1989-08-30
|
3KB
|
138 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "lsdelcur.c 1.1 - 89/07/03" */
#include <blkio.h>
#include <errno.h>
#include "lseq_.h"
/*man---------------------------------------------------------------------------
NAME
lsdelcur - delete current lseq record
SYNOPSIS
#include <lseq.h>
int lsdelcur(lsp)
lseq_t *lsp;
DESCRIPTION
The lsdelcur function deletes the current record from lseq lsp. The
The cursor is positioned to the record following the deleted record.
lsdelcur will fail if one or more of the following is true:
[EINVAL] lsp is not a valid lseq pointer.
[LSELOCK] lsp is not write locked.
[LSENOPEN] lsp is not open.
[LSENREC] The cursor is null.
SEE ALSO
lsinscur, lsinsert, lssearch.
DIAGNOSTICS
Upon successful completion, a value of 0 is returned. Otherwise, a
value of -1 is returned and errno is set to indicate the error.
------------------------------------------------------------------------------*/
int lsdelcur(lsp)
lseq_t * lsp;
{
int rs = 0;
bpos_t bpos = 0;
errno = 0;
/* validate arguments */
if (!ls_valid(lsp)) {
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(lsp->flags & LSOPEN)) {
errno = LSENOPEN;
return -1;
}
/* check if not write locked */
if (!(lsp->flags & LSWRLCK)) {
errno = LSELOCK;
return -1;
}
/* check if cursor is NULL */
if (lsp->clspos == 0) {
errno = LSENREC;
return -1;
}
/* set modify bit in header */
lsp->lshdr.flags |= LSHMOD;
rs = bputh(lsp->bp, (void *)&lsp->lshdr);
if (rs == -1) {
LSEPRINT;
return -1;
}
rs = bsync(lsp->bp);
if (rs == -1) {
LSEPRINT;
return -1;
}
/* fix links */
if (lsp->clsrp->next == 0) {
lsp->lshdr.last = lsp->clsrp->prev;
} else {
rs = bputbf(lsp->bp, (bpos_t)lsp->clsrp->next, offsetof(lsrec_t, prev), (void *)&lsp->clsrp->prev, sizeof(lsp->clsrp->prev));
if (rs == -1) {
LSEPRINT;
return -1;
}
}
if (lsp->clsrp->prev == 0) {
lsp->lshdr.first = lsp->clsrp->next;
} else {
rs = bputbf(lsp->bp, (bpos_t)lsp->clsrp->prev, offsetof(lsrec_t, next), (void *)&lsp->clsrp->next, sizeof(lsp->clsrp->next));
if (rs == -1) {
LSEPRINT;
return -1;
}
}
/* decrement record count */
lsp->lshdr.reccnt--;
/* return block to free list */
bpos = lsp->clspos;
rs = bflpush(lsp->bp, &bpos);
if (rs == -1) {
LSEPRINT;
return -1;
}
/* clear modify bit in header */
lsp->lshdr.flags &= ~LSHMOD;
rs = bputh(lsp->bp, (void *)&lsp->lshdr);
if (rs == -1) {
LSEPRINT;
return -1;
}
rs = bsync(lsp->bp);
if (rs == -1) {
LSEPRINT;
return -1;
}
/* position cursor to next record */
rs = lsnext(lsp);
if (rs == -1) {
LSEPRINT;
return -1;
}
errno = 0;
return 0;
}