home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CBASE101.ZIP / LSEQ101.ZIP / LSSETVBU.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  88 lines

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