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

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. #include <stdio.h>
  4. #include <limits.h>
  5. #include <memory.h>
  6.  
  7. int setvbuf(fp, bp, bmode, size)
  8. register FILE *fp;
  9. char *bp;
  10. int bmode;
  11. size_t size;
  12. {
  13.     if(fp->_flag & _IOMYBUF)
  14.     free(fp->_base);
  15.     fp->_flag &= ~(_IOFBF | _IOLBF | _IONBF | _IOMYBUF);
  16.     fp->_flag |= bmode;
  17.     fp->_cnt = 0;
  18.     if(bmode == _IONBF)                /* unbuffered */
  19.     {
  20.     fp->_base = &(fp->_ch);            /* use tiny buffer */
  21.     fp->_bsiz = 1;
  22.     }
  23.     
  24.     else if (size > (size_t) LONG_MAX)              /* not likely! */
  25.     return -1;
  26.     
  27.     else                        /* full buffering */
  28.     {
  29.     if(bp != NULL)
  30.     {
  31.         fp->_base = (unsigned char *) bp;
  32.     }
  33.     else
  34.     {
  35.         if ((fp->_base = (unsigned char *) malloc(size)) != NULL)
  36.         {
  37.         fp->_flag |= _IOMYBUF;
  38.         }
  39.         else
  40.         {
  41.         return -1;
  42.         }
  43.     }
  44.     fp->_bsiz = size;
  45.     }
  46.     fp->_ptr = fp->_base;
  47.     return 0;
  48. }
  49.