home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
LSEQ.ZIP
/
LSOPS.C
< prev
next >
Wrap
Text File
|
1989-08-30
|
3KB
|
158 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "lsops.c 1.1 - 89/07/03" */
#include <blkio.h>
#include <bool.h>
#include <errno.h>
/* #include <stdlib.h> */
#include "lseq_.h"
/*man---------------------------------------------------------------------------
NAME
ls_alloc - allocate memory for a lseq
SYNOPSIS
#include "lseq_.h"
int ls_alloc(lsp);
lseq_t *lsp;
DESCRIPTION
The ls_alloc function allocates the memory needed by lseq lsp. The
memory is initialized to 0.
ls_alloc will fail if one or more of the following is true:
[EINVAL] lsp is not a valid lseq pointer.
[ENOMEM] Not enough memory is available for the
calling process to allocate.
[LSENOPEN] lsp is not open.
SEE ALSO
ls_free.
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 ls_alloc(lsp)
lseq_t *lsp;
{
errno = 0;
#ifdef DEBUG
/* validate arguments */
if (!ls_valid(lsp)) {
LSEPRINT;
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(lsp->flags & LSOPEN)) {
LSEPRINT;
errno = LSENOPEN;
return -1;
}
#endif
/* free any previously allocated storage */
ls_free(lsp);
/* current record */
lsp->clsrp = ls_rcalloc(lsp);
if (lsp->clsrp == NULL) {
LSEPRINT;
return -1;
}
errno = 0;
return 0;
}
/*man---------------------------------------------------------------------------
NAME
ls_blksize - lseq block size
SYNOPSIS
#include <lseq.h>
void *ls_blksize(lsp)
lseq_t *lsp;
DESCRIPTION
ls_blksize returns the size of the blocks in lseq lsp. If lsp is not
a valid open lseq, the results are undefined. ls_blksize is a macro.
------------------------------------------------------------------------------*/
/* ls_blksize #defined in lseq_.h. */
/*man---------------------------------------------------------------------------
NAME
ls_free - free memory allocated for an lseq
SYNOPSIS
#include "lseq_.h"
void ls_free(lsp)
lseq_t *lsp;
DESCRIPTION
The ls_free function frees all memory allocated for lseq lsp.
If lsp is not a valid lseq, no action is taken.
SEE ALSO
ls_alloc.
------------------------------------------------------------------------------*/
void ls_free(lsp)
lseq_t *lsp;
{
/* validate arguments */
if (!ls_valid(lsp)) {
LSEPRINT;
return;
}
/* free memory */
if (lsp->clsrp != NULL) {
ls_rcfree(lsp->clsrp);
lsp->clsrp = NULL;
}
return;
}
/*man---------------------------------------------------------------------------
NAME
ls_valid - validate lseq
SYNOPSIS
#include "lseq_.h"
bool ls_valid(lsp)
lseq_t *lsp;
DESCRIPTION
The ls_valid function determines if lsp points to a valid lseq
control structure. If it is valid, TRUE is returned. If not,
then FALSE is returned.
------------------------------------------------------------------------------*/
bool ls_valid(lsp)
lseq_t *lsp;
{
if ((lsp < lsb) || (lsp > (lsb + LSOPEN_MAX - 1))) {
return FALSE;
}
if (((size_t)((char *)lsp - (char *)lsb)) % sizeof(lsb[0]) != 0) {
return FALSE;
}
return TRUE;
}