ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_flsbuf.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       GNU GPL, see COPYING in the top level directory
00003  * PROJECT:         ReactOS crt library
00004  * FILE:            lib/sdk/crt/stdio/_flsbuf.c
00005  * PURPOSE:         Implementation of _flsbuf / _flswbuf
00006  * PROGRAMMER:      Timo Kreuzer
00007  */
00008 
00009 #include <precomp.h>
00010 
00011 void __cdecl alloc_buffer(FILE *stream);
00012 
00013 int __cdecl
00014 _flsbuf(int ch, FILE *stream)
00015 {
00016     int count, written;
00017 
00018     /* Check if the stream supports flushing */
00019     if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT)))
00020     {
00021         stream->_flag |= _IOERR;
00022         return EOF;
00023     }
00024 
00025     /* Always reset _cnt */
00026     stream->_cnt = 0;
00027 
00028     /* Check if this was a read buffer */
00029     if (stream->_flag & _IOREAD)
00030     {
00031         /* Must be at the end of the file */
00032         if (!(stream->_flag & _IOEOF))
00033         {
00034             stream->_flag |= _IOERR;
00035             return EOF;
00036         }
00037 
00038         /* Reset buffer */
00039         stream->_ptr = stream->_base;
00040     }
00041 
00042     /* Fixup flags */
00043     stream->_flag &= ~(_IOREAD|_IOEOF);
00044     stream->_flag |= _IOWRT;
00045 
00046     /* Check if should get a buffer */
00047     if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr)
00048     {
00049         /* If we have no buffer, try to allocate one */
00050         if (!stream->_base) alloc_buffer(stream);
00051     }
00052 
00053     /* Check if we can use a buffer now */
00054     if (stream->_base && !(stream->_flag & _IONBF))
00055     {
00056         /* We can, check if there is something to write */
00057         count = (int)(stream->_ptr - stream->_base);
00058         if (count > 0)
00059             written = _write(stream->_file, stream->_base, count);
00060         else
00061             written = 0;
00062 
00063         /* Reset buffer and put the char into it */
00064         stream->_ptr = stream->_base + sizeof(TCHAR);
00065         stream->_cnt = stream->_bufsiz - sizeof(TCHAR);
00066         *(TCHAR*)stream->_base = ch;
00067     }
00068     else
00069     {
00070         /* There is no buffer, write the char directly */
00071         count = sizeof(TCHAR);
00072         written = _write(stream->_file, &ch, sizeof(TCHAR));
00073     }
00074 
00075     /* Check for failure */
00076     if (written != count)
00077     {
00078         stream->_flag |= _IOERR;
00079         return EOF;
00080     }
00081 
00082     return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff);
00083 }

Generated on Sun May 27 2012 04:36:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.