home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CBASE09.ZIP / LSEQ.ZIP / LSSETVBU.C < prev    next >
Text File  |  1989-08-30  |  2KB  |  90 lines

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