home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / IOSTRSR1.ZIP / SDBUFLOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.6 KB  |  62 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     sdbuflow.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class stdiobuf                                           |*/
  6. /*|          int stdiobuf::underflow()                           |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <filesys.h>
  20. #include <stdiostr.h>
  21.  
  22. int stdiobuf::underflow()
  23. {
  24.     if( in_avail() )    // no action needed
  25.         return (unsigned char) *gptr();
  26.  
  27.     int c;  // the return value
  28.  
  29.     if ( ! unbuffered()  &&  base() )
  30.         {     // this is buffered
  31.         // flush any output buffer
  32.         if( out_waiting() )
  33.             if( overflow(EOF) == EOF )
  34.                 return EOF;
  35.  
  36.         // read in a character
  37.         c = getc(sio);
  38.  
  39.         // find buffer
  40.         char *b = base();
  41.         *b = c;
  42.  
  43.         // set up get and put areas
  44.         setg(b, b+4, b+5);
  45.         setp(b+4, b+4);
  46.         }
  47.     else
  48.         {      // this is not buffered
  49.         // read in a character
  50.         c = getc(sio);
  51.         if( c == EOF )
  52.             setg(0, 0, 0);
  53.         else
  54.             {
  55.             lahead[0] = c;
  56.             setg(lahead, lahead, lahead+1);
  57.             }
  58.         }
  59.  
  60.     return c;
  61. }
  62.