home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / getbuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  818 b   |  34 lines

  1. /* from the dLibs getbuf.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7.  
  8. extern size_t __DEFAULT_BUFSIZ__;
  9.  
  10. void _getbuf(fp)        /* allocate a buffer for a stream */
  11. register FILE *fp;
  12. {
  13.     unsigned int f = fp->_flag;
  14.     
  15.     if(f & _IOLBF)
  16.     fp->_bsiz = (__DEFAULT_BUFSIZ__ < BUFSIZ) ? __DEFAULT_BUFSIZ__ :
  17.         BUFSIZ;
  18.     else
  19.     fp->_bsiz = __DEFAULT_BUFSIZ__;
  20.     
  21.     if((f & _IONBF) /* risky!! but works ok with gnu.may change */
  22.        || ((fp->_base = malloc((size_t)fp->_bsiz)) == NULL) )
  23.     {
  24.     fp->_flag &= ~(_IOFBF | _IOLBF | _IONBF);
  25.     fp->_flag |= _IONBF;
  26.     fp->_base = &(fp->_ch);            /* use tiny buffer */
  27.     fp->_bsiz = 1;
  28.     }
  29.     else
  30.     fp->_flag |= _IOMYBUF;            /* use big buffer */
  31.     fp->_ptr = fp->_base;
  32.     fp->_cnt = 0;        /* start out with an empty buffer */
  33. }
  34.