home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_1.iso / msdos / c / cbase11.a03 / CBASE11.ZIP / LSEQ / LSSETVBU.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  2KB  |  97 lines

  1. /*
  2.  *    Copyright (c) 1989-1992 Citadel Software, Inc.
  3.  *    All Rights Reserved
  4.  */
  5.  
  6. /* #ident    "@(#)lssetvbu.c    1.7 - 93/01/01" */
  7.  
  8. #include <port.h>
  9.  
  10. /* standard headers */
  11. #include <errno.h>
  12. #ifdef AC_STDDEF
  13. #include <stddef.h>
  14. #endif
  15.  
  16. /* local headers */
  17. #include <blkio.h>
  18.  
  19. /* local headers */
  20. #include "lseq_.h"
  21.  
  22. /*man---------------------------------------------------------------------------
  23. NAME
  24.      lssetvbuf - assign buffering to an lseq
  25.  
  26. SYNOPSIS
  27.      #include <lseq.h>
  28.  
  29.      int lssetvbuf(lsp, buf, bufcnt)
  30.      lseq_t *lsp;
  31.      void *buf;
  32.      size_t bufcnt;
  33.  
  34. DESCRIPTION
  35.      The lssetvbuf function is used to assign buffering to an lseq.
  36.      bufcnt specifies the number of lseq records to be buffered.  If
  37.      bufcnt has a value of zero, the lseq will be completely
  38.      unbuffered.  If buf is not the NULL pointer, the storage area it
  39.      points to will be used instead of one automatically allocated for
  40.      buffering.
  41.  
  42.      The size of the storage area needed can be obtained using the
  43.      LSBUFSIZE() macro:
  44.  
  45.           char buf[LSBUFSIZE(RECSIZE, BUFCNT)];
  46.           lssetvbuf(lsp, buf, BUFCNT);
  47.  
  48.      where RECSIZE is the size of the keys int the lseq, and BUFCNT is
  49.      the number of records to buffer.
  50.  
  51.      Any previously buffered data is flushed before installing the new
  52.      buffer area, so lssetvbuf may be called more than once.  This
  53.      allows the buffer size to be varied with the file size.
  54.  
  55.      lssetvbuf will fail if one or more of the following is true:
  56.  
  57.      [EINVAL]       lsp is not a valid lseq pointer.
  58.      [LSENOPEN]     lsp is not open.
  59.  
  60. SEE ALSO
  61.      lssetbuf, lssync.
  62.  
  63. DIAGNOSTICS
  64.      Upon successful completion, a value of 0 is returned.  Otherwise,
  65.      a value of -1 is returned, and errno set to indicate the error.
  66.  
  67. ------------------------------------------------------------------------------*/
  68. #ifdef AC_PROTO
  69. int lssetvbuf(lseq_t *lsp, void *buf, size_t bufcnt)
  70. #else
  71. int lssetvbuf(lsp, buf, bufcnt)
  72. lseq_t *lsp;
  73. void *buf;
  74. size_t bufcnt;
  75. #endif
  76. {
  77.     /* validate arguments */
  78.     if (!ls_valid(lsp)) {
  79.         errno = EINVAL;
  80.         return -1;
  81.     }
  82.  
  83.     /* check if not open */
  84.     if (!(lsp->flags & LSOPEN)) {
  85.         errno = LSENOPEN;
  86.         return -1;
  87.     }
  88.  
  89.     /* set buffering */
  90.     if (bsetvbuf(lsp->bp, buf, ls_blksize(lsp), bufcnt) == -1) {
  91.         LSERRLOG;
  92.         return -1;
  93.     }
  94.  
  95.     return 0;
  96. }
  97.