home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / stdio / setvbuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.5 KB  |  92 lines

  1.  
  2. /*
  3.  *  SETVBUF
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  *
  7.  *  Hacked because my stdio utilizes two buffers to support full
  8.  *  duplex streams.
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <errno.h>
  13.  
  14. int
  15. setvbuf(fi, buf, mode, bytes)
  16. FILE *fi;
  17. char *buf;
  18. int mode;
  19. long bytes;
  20. {
  21.     fflush(fi);
  22.  
  23.     switch(mode) {
  24.     case _IOFBF:
  25.     fi->sd_Flags &= ~__SIF_IOLBF;
  26.     case _IOLBF:
  27.     if (mode == _IOLBF)
  28.         fi->sd_Flags |= __SIF_IOLBF;
  29.     if (bytes) {
  30.         if (fi->sd_Flags & __SIF_MYBUF) {
  31.         if (fi->sd_RBuf) {
  32.             free(fi->sd_RBuf);
  33.         }
  34.  
  35.         if (fi->sd_WBuf) {
  36.             free(fi->sd_WBuf);
  37.         }
  38.         }
  39.         /*
  40.         fi->sd_Flags &= ~__SIF_MYBUF;
  41.         */
  42.         fi->sd_BufSiz = bytes;
  43.         fi->sd_WLeft = -1;
  44.         fi->sd_RLeft = -1;
  45.  
  46.         /*
  47.         fi->sd_WBuf = buf;
  48.         fi->sd_WPtr = buf;
  49.         */
  50.         fi->sd_WBuf = NULL;
  51.         fi->sd_WPtr = NULL;
  52.         fi->sd_RBuf = NULL;
  53.         fi->sd_RPtr = NULL;
  54.     }
  55.     /*
  56.      *  put terminal back into cooked mode XXX
  57.      */
  58.     break;
  59.     case _IONBF:
  60.     fi->sd_Flags &= ~__SIF_IOLBF;
  61.     fi->sd_BufSiz = 0;
  62.     if (fi->sd_Flags & __SIF_MYBUF) {
  63.         if (fi->sd_RBuf) {
  64.         free(fi->sd_RBuf);
  65.         fi->sd_RBuf = NULL;
  66.         fi->sd_RPtr = NULL;
  67.         }
  68.         if (fi->sd_WBuf) {
  69.         free(fi->sd_WBuf);
  70.         fi->sd_WBuf = NULL;
  71.         }
  72.     }
  73.     fi->sd_Flags &= ~__SIF_MYBUF;
  74.     fi->sd_WBuf = NULL;
  75.     fi->sd_WPtr = NULL;
  76.     fi->sd_RBuf = NULL;
  77.     fi->sd_RPtr = NULL;
  78.     fi->sd_WLeft = -1;
  79.     fi->sd_RLeft = -1;
  80.  
  81.     /*
  82.      *  attempt to place terminal in RAW mode XXX
  83.      */
  84.  
  85.     break;
  86.     default:
  87.     return(EOF);
  88.     }
  89.     return(0);
  90. }
  91.  
  92.