home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Press 1997 July
/
Sezamfile97_1.iso
/
msdos
/
c
/
cbase11.a03
/
CBASE11.ZIP
/
LSEQ
/
LSOPS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-01
|
4KB
|
181 lines
/*
* Copyright (c) 1989-1992 Citadel Software, Inc.
* All Rights Reserved
*/
/* #ident "@(#)lsops.c 1.7 - 93/01/01" */
#include <port.h>
/* standard headers */
#include <errno.h>
#ifdef AC_STDLIB
#include <stdlib.h>
#endif
/* standard headers */
#include <bool.h>
/* library headers */
#include <blkio.h>
/* local headers */
#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
allocation by the calling process.
[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.
------------------------------------------------------------------------------*/
#ifdef AC_PROTO
int ls_alloc(lseq_t *lsp)
#else
int ls_alloc(lsp)
lseq_t *lsp;
#endif
{
#ifdef DEBUG
/* validate arguments */
if (!ls_valid(lsp)) {
LSERRLOG;
errno = EINVAL;
return -1;
}
/* check if not open */
if (!(lsp->flags & LSOPEN)) {
LSERRLOG;
errno = LSENOPEN;
return -1;
}
/* check for memory leak */
if (lsp->clsrp != NULL) {
LSERRLOG;
errno = LSEFATAL;
return -1;
}
#endif
/* current record */
lsp->clsrp = ls_rcalloc(lsp);
if (lsp->clsrp == NULL) {
LSERRLOG;
return -1;
}
return 0;
}
/*man---------------------------------------------------------------------------
NAME
ls_blksize - lseq block size
SYNOPSIS
#include <lseq.h>
size_t 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.
------------------------------------------------------------------------------*/
#ifdef AC_PROTO
void ls_free(lseq_t *lsp)
#else
void ls_free(lsp)
lseq_t *lsp;
#endif
{
#ifdef DEBUG
/* validate arguments */
if (!ls_valid(lsp)) {
LSERRLOG;
return;
}
#endif
/* free memory */
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 is a valid lseq pointer.
If valid, then TRUE is returned. If not, then FALSE is returned.
------------------------------------------------------------------------------*/
#ifdef AC_PROTO
bool ls_valid(lseq_t *lsp)
#else
bool ls_valid(lsp)
lseq_t *lsp;
#endif
{
if (lsp < lsb || lsp > (lsb + LSOPEN_MAX - 1)) {
return FALSE;
}
if ((((char *)lsp - (char *)lsb)) % sizeof(*lsb) != 0) {
return FALSE;
}
return TRUE;
}