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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "lssetbuf.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.      lssetbuf - assign buffering to an lseq
  13.  
  14. SYNOPSIS
  15.      #include <lseq.h>
  16.  
  17.      int lssetbuf(lsp, buf)
  18.      lseq_t *lsp;
  19.      void *buf;
  20.  
  21. DESCRIPTION
  22.      The lssetbuf function causes the storage area pointed to by buf to be
  23.      used by lseq lsp instead of an automatically allocated buffer area.  If
  24.      buf is the NULL pointer, lsp will be completely unbuffered.
  25.  
  26.      The size of the storage area needed can be obtained using the
  27.      LSBUFSIZE() macro:
  28.  
  29.           char buf[LSBUFSIZE(RECSIZE, LSBUFCNT)];
  30.           .
  31.           .
  32.           .
  33.           lssetbuf(lsp, (void *)buf);
  34.  
  35.      where RECSIZE is the size of the records in the lseq and LSBUFCNT is
  36.      the default number of records buffered when an lseq is opened.
  37.      LSBUFCNT is #defined in lseq.h.  If the number of records buffered has
  38.      been changed using lssetvbuf, then that number should be used in place
  39.      of LSBUFCNT.
  40.  
  41.      Any previously buffered data is written out before installing the new
  42.      buffer area.
  43.  
  44.      lssetbuf will fail if one or more of the following is true:
  45.  
  46.      [EINVAL]       lsp is not a valid lseq pointer.
  47.      [LSENBUF]      buf is not the NULL pointer and lsp
  48.                     is not buffered.
  49.      [LSENOPEN]     lsp is not open.
  50.  
  51. SEE ALSO
  52.      lssetvbuf, 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 lssetbuf(lsp, buf)
  60. lseq_t * lsp;
  61. void *   buf;
  62. {
  63.     int rs = 0;
  64.  
  65.     errno = 0;
  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.     /* assign buffering */
  80.     rs = bsetbuf(lsp->bp, buf);
  81.     if (rs == -1) {
  82.         if (errno == BENBUF) errno = LSENBUF;
  83.         LSEPRINT;
  84.         return -1;
  85.     }
  86.  
  87.     errno = 0;
  88.     return 0;
  89. }
  90.