2011-01-04 22:22:13 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS crt library
|
|
|
|
* FILE: lib/sdk/crt/stdio/_flsbuf.c
|
|
|
|
* PURPOSE: Implementation of _flsbuf / _flswbuf
|
|
|
|
* PROGRAMMER: Timo Kreuzer
|
|
|
|
*/
|
|
|
|
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
#include <precomp.h>
|
2011-01-04 22:22:13 +00:00
|
|
|
|
2016-09-06 10:04:29 +00:00
|
|
|
BOOL __cdecl msvcrt_alloc_buffer(FILE *stream);
|
2011-01-04 22:22:13 +00:00
|
|
|
|
|
|
|
int __cdecl
|
|
|
|
_flsbuf(int ch, FILE *stream)
|
|
|
|
{
|
|
|
|
int count, written;
|
|
|
|
|
|
|
|
/* Check if the stream supports flushing */
|
|
|
|
if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT)))
|
|
|
|
{
|
|
|
|
stream->_flag |= _IOERR;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
2011-06-01 12:08:02 +00:00
|
|
|
/* Always reset _cnt */
|
|
|
|
stream->_cnt = 0;
|
|
|
|
|
2011-04-21 21:49:46 +00:00
|
|
|
/* Check if this was a read buffer */
|
2011-01-04 22:22:13 +00:00
|
|
|
if (stream->_flag & _IOREAD)
|
|
|
|
{
|
|
|
|
/* Must be at the end of the file */
|
|
|
|
if (!(stream->_flag & _IOEOF))
|
|
|
|
{
|
|
|
|
stream->_flag |= _IOERR;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset buffer */
|
|
|
|
stream->_ptr = stream->_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fixup flags */
|
|
|
|
stream->_flag &= ~(_IOREAD|_IOEOF);
|
|
|
|
stream->_flag |= _IOWRT;
|
|
|
|
|
2011-06-01 12:08:02 +00:00
|
|
|
/* Check if should get a buffer */
|
|
|
|
if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr)
|
2011-01-04 22:22:13 +00:00
|
|
|
{
|
2011-06-01 12:08:02 +00:00
|
|
|
/* If we have no buffer, try to allocate one */
|
2016-09-06 10:04:29 +00:00
|
|
|
if (!stream->_base) msvcrt_alloc_buffer(stream);
|
2011-01-04 22:22:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 12:08:02 +00:00
|
|
|
/* Check if we can use a buffer now */
|
|
|
|
if (stream->_base && !(stream->_flag & _IONBF))
|
2011-01-04 22:22:13 +00:00
|
|
|
{
|
2011-06-01 12:08:02 +00:00
|
|
|
/* We can, check if there is something to write */
|
2011-09-15 17:11:53 +00:00
|
|
|
count = (int)(stream->_ptr - stream->_base);
|
2011-01-04 22:22:13 +00:00
|
|
|
if (count > 0)
|
|
|
|
written = _write(stream->_file, stream->_base, count);
|
|
|
|
else
|
|
|
|
written = 0;
|
|
|
|
|
|
|
|
/* Reset buffer and put the char into it */
|
|
|
|
stream->_ptr = stream->_base + sizeof(TCHAR);
|
|
|
|
stream->_cnt = stream->_bufsiz - sizeof(TCHAR);
|
|
|
|
*(TCHAR*)stream->_base = ch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* There is no buffer, write the char directly */
|
|
|
|
count = sizeof(TCHAR);
|
|
|
|
written = _write(stream->_file, &ch, sizeof(TCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for failure */
|
|
|
|
if (written != count)
|
|
|
|
{
|
|
|
|
stream->_flag |= _IOERR;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
|
2011-01-07 21:15:35 +00:00
|
|
|
return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff);
|
2011-01-04 22:22:13 +00:00
|
|
|
}
|