home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / FBUF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  764 b   |  32 lines

  1. /* fbuf.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. /* Assign a buffer to a stream (which must not have a buffer) */
  8.  
  9. void _fbuf (FILE *stream)
  10. {
  11.   if (stream->flags & _IONBF)
  12.     stream->buffer = NULL;
  13.   else
  14.     stream->buffer = malloc (BUFSIZ);
  15.   if (stream->buffer == NULL)
  16.     {
  17.       stream->buf_size = 1;
  18.       stream->buffer = &stream->char_buf;
  19.       stream->flags &= ~(_IOFBF|_IOLBF|_IOBUFMASK);
  20.       stream->flags |= _IONBF|_IOBUFCHAR;
  21.     }
  22.   else
  23.     {
  24.       stream->buf_size = BUFSIZ;
  25.       stream->flags &= ~_IOBUFMASK;
  26.       stream->flags |= _IOBUFLIB;
  27.     }
  28.   stream->ptr = stream->buffer;
  29.   stream->rcount = 0;
  30.   stream->wcount = 0;
  31. }
  32.