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 >
C/C++ Source or Header  |  1993-01-01  |  4KB  |  181 lines

  1. /*
  2.  *    Copyright (c) 1989-1992 Citadel Software, Inc.
  3.  *    All Rights Reserved
  4.  */
  5.  
  6. /* #ident    "@(#)lsops.c    1.7 - 93/01/01" */
  7.  
  8. #include <port.h>
  9.  
  10. /* standard headers */
  11. #include <errno.h>
  12. #ifdef AC_STDLIB
  13. #include <stdlib.h>
  14. #endif
  15.  
  16. /* standard headers */
  17. #include <bool.h>
  18.  
  19. /* library headers */
  20. #include <blkio.h>
  21.  
  22. /* local headers */
  23. #include "lseq_.h"
  24.  
  25. /*man---------------------------------------------------------------------------
  26. NAME
  27.      ls_alloc - allocate memory for a lseq
  28.  
  29. SYNOPSIS
  30.      #include "lseq_.h"
  31.  
  32.      int ls_alloc(lsp);
  33.      lseq_t *lsp;
  34.  
  35. DESCRIPTION
  36.      The ls_alloc function allocates the memory needed by lseq lsp.
  37.      The memory is initialized to 0.
  38.  
  39.      ls_alloc will fail if one or more of the following is true:
  40.  
  41.      [EINVAL]       lsp is not a valid lseq pointer.
  42.      [ENOMEM]       Not enough memory is available for
  43.                     allocation by the calling process.
  44.      [LSENOPEN]     lsp is not open.
  45.  
  46. SEE ALSO
  47.      ls_free.
  48.  
  49. DIAGNOSTICS
  50.      Upon successful completion, a value of 0 is returned.  Otherwise,
  51.      a value of -1 is returned, and errno set to indicate the error.
  52.  
  53. ------------------------------------------------------------------------------*/
  54. #ifdef AC_PROTO
  55. int ls_alloc(lseq_t *lsp)
  56. #else
  57. int ls_alloc(lsp)
  58. lseq_t *lsp;
  59. #endif
  60. {
  61. #ifdef DEBUG
  62.     /* validate arguments */
  63.     if (!ls_valid(lsp)) {
  64.         LSERRLOG;
  65.         errno = EINVAL;
  66.         return -1;
  67.     }
  68.  
  69.     /* check if not open */
  70.     if (!(lsp->flags & LSOPEN)) {
  71.         LSERRLOG;
  72.         errno = LSENOPEN;
  73.         return -1;
  74.     }
  75.  
  76.     /* check for memory leak */
  77.     if (lsp->clsrp != NULL) {
  78.         LSERRLOG;
  79.         errno = LSEFATAL;
  80.         return -1;
  81.     }
  82. #endif
  83.     /* current record */
  84.     lsp->clsrp = ls_rcalloc(lsp);
  85.     if (lsp->clsrp == NULL) {
  86.         LSERRLOG;
  87.         return -1;
  88.     }
  89.  
  90.     return 0;
  91. }
  92.  
  93. /*man---------------------------------------------------------------------------
  94. NAME
  95.      ls_blksize - lseq block size
  96.  
  97. SYNOPSIS
  98.      #include <lseq.h>
  99.  
  100.      size_t ls_blksize(lsp)
  101.      lseq_t *lsp;
  102.  
  103. DESCRIPTION
  104.      ls_blksize returns the size of the blocks in lseq lsp.  If lsp is
  105.      not a valid open lseq, the results are undefined.  ls_blksize is
  106.      a macro.
  107.  
  108. ------------------------------------------------------------------------------*/
  109. /* ls_blksize defined in lseq_.h. */
  110.  
  111. /*man---------------------------------------------------------------------------
  112. NAME
  113.      ls_free - free memory allocated for an lseq
  114.  
  115. SYNOPSIS
  116.      #include "lseq_.h"
  117.  
  118.      void ls_free(lsp)
  119.      lseq_t *lsp;
  120.  
  121. DESCRIPTION
  122.      The ls_free function frees all memory allocated for lseq lsp.
  123.      If lsp is not a valid lseq, no action is taken.
  124.  
  125. SEE ALSO
  126.      ls_alloc.
  127.  
  128. ------------------------------------------------------------------------------*/
  129. #ifdef AC_PROTO
  130. void ls_free(lseq_t *lsp)
  131. #else
  132. void ls_free(lsp)
  133. lseq_t *lsp;
  134. #endif
  135. {
  136. #ifdef DEBUG
  137.     /* validate arguments */
  138.     if (!ls_valid(lsp)) {
  139.         LSERRLOG;
  140.         return;
  141.     }
  142. #endif
  143.     /* free memory */
  144.     ls_rcfree(lsp->clsrp);
  145.     lsp->clsrp = NULL;
  146.  
  147.     return;
  148. }
  149.  
  150. /*man---------------------------------------------------------------------------
  151. NAME
  152.      ls_valid - validate lseq
  153.  
  154. SYNOPSIS
  155.      #include "lseq_.h"
  156.  
  157.      bool ls_valid(lsp)
  158.      lseq_t *lsp;
  159.  
  160. DESCRIPTION
  161.      The ls_valid function determines if lsp is a valid lseq pointer.
  162.      If valid, then TRUE is returned.  If not, then FALSE is returned.
  163.  
  164. ------------------------------------------------------------------------------*/
  165. #ifdef AC_PROTO
  166. bool ls_valid(lseq_t *lsp)
  167. #else
  168. bool ls_valid(lsp)
  169. lseq_t *lsp;
  170. #endif
  171. {
  172.     if (lsp < lsb || lsp > (lsb + LSOPEN_MAX - 1)) {
  173.         return FALSE;
  174.     }
  175.     if ((((char *)lsp - (char *)lsb)) % sizeof(*lsb) != 0) {
  176.         return FALSE;
  177.     }
  178.  
  179.     return TRUE;
  180. }
  181.