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

  1. /* tmpbuf.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <sys/ioctl.h>
  6. #include <io.h>
  7.  
  8. static char stdout_buf[BUFSIZ];
  9. static char stderr_buf[BUFSIZ];
  10.  
  11. void _tmpbuf (FILE *stream)
  12. {
  13.   char *buf;
  14.   int ft;
  15.  
  16.   if ((stream->flags & _IONBF) && (nbuf (stream) || cbuf (stream)) &&
  17.       (stream == stdout || stream == stderr))
  18.     {
  19.       buf = (stream == stdout ? stdout_buf : stderr_buf);
  20.       stream->ptr = stream->buffer = buf;
  21.       stream->wcount = BUFSIZ;
  22.       stream->rcount = 0;
  23.       stream->flags |= _IOWRT;
  24.       stream->flags &= ~(_IONBF|_IOLBF|_IOFBF|_IOBUFMASK|_IOEOF);
  25.       if (ioctl (fileno (stream), FGETHTYPE, &ft) >= 0 && ft != HT_FILE)
  26.         stream->flags |= _IOFBF|_IOBUFTMP;
  27.       else
  28.         stream->flags |= _IOFBF|_IOBUFUSER;
  29.     }
  30. }
  31.  
  32. void _endbuf (FILE *stream)
  33. {
  34.   if ((stream->flags & _IOBUFMASK) == _IOBUFTMP)
  35.     {
  36.       fflush (stream);
  37.       stream->buf_size = 1;
  38.       stream->ptr = stream->buffer = &stream->char_buf;
  39.       stream->flags &= ~(_IOFBF|_IOLBF|_IOBUFMASK);
  40.       stream->flags |= _IONBF|_IOBUFCHAR;
  41.       stream->rcount = stream->wcount = 0;
  42.     }
  43. }
  44.