home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / setbuf.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  984b  |  52 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include <stdlib.h>
  6.  
  7. void setbuf(fp, buf)
  8.     register FILE *fp;
  9.     char *buf;
  10.     {
  11.     assert((fp != NULL));
  12.         
  13.     if(fp->_flag & _IOMYBUF)
  14.         free(fp->_base);
  15.     fp->_flag &= ~(_IOFBF | _IOLBF | _IONBF | _IOMYBUF);
  16.     fp->_cnt = 0;
  17.     if((fp->_base = (unsigned char *)buf) != NULL)
  18.         {
  19.         fp->_flag |= _IOFBF;
  20.             /* this is intentionally not __DEFAULT_BUFSIZ__ ++jrb */
  21.         fp->_bsiz = BUFSIZ;
  22.         }
  23.     else
  24.         {
  25.         fp->_flag |= _IONBF;
  26.         fp->_base = &(fp->_ch);            /* use tiny buffer */
  27.         fp->_bsiz = 1;
  28.         }
  29.     fp->_ptr = fp->_base;
  30.     }
  31.  
  32. /*
  33.  * bezerkly'ism
  34.  * change the buffering on stream from block/unbuffered to line buffered.
  35.  * should stream be flushed before change?? i think so.
  36.  *    ++jrb
  37.  */
  38.  
  39. void setlinebuf(fp)
  40. register FILE *fp;
  41. {
  42.     assert((fp != NULL));
  43.  
  44. #ifndef NDEBUG
  45.     assert((fflush(fp) != EOF));
  46. #else    
  47.     (void)fflush(fp);
  48. #endif
  49.     fp->_flag &= ~(_IOFBF | _IONBF);
  50.     fp->_flag |=  _IOLBF;
  51. }
  52.