msvcrt: Make _flsbuf thread safe.
This commit is contained in:
parent
f773ad8388
commit
c989c4980b
|
@ -3025,6 +3025,8 @@ int CDECL MSVCRT_fputc(int c, MSVCRT_FILE* file)
|
||||||
*/
|
*/
|
||||||
int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
|
int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
|
||||||
{
|
{
|
||||||
|
MSVCRT__lock_file(file);
|
||||||
|
|
||||||
/* Flush output buffer */
|
/* Flush output buffer */
|
||||||
if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) {
|
if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) {
|
||||||
msvcrt_alloc_buffer(file);
|
msvcrt_alloc_buffer(file);
|
||||||
|
@ -3033,20 +3035,28 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
|
||||||
if(file->_flag & MSVCRT__IORW) {
|
if(file->_flag & MSVCRT__IORW) {
|
||||||
file->_flag |= MSVCRT__IOWRT;
|
file->_flag |= MSVCRT__IOWRT;
|
||||||
} else {
|
} else {
|
||||||
|
MSVCRT__unlock_file(file);
|
||||||
return MSVCRT_EOF;
|
return MSVCRT_EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(file->_bufsiz) {
|
if(file->_bufsiz) {
|
||||||
int res=msvcrt_flush_buffer(file);
|
int res=msvcrt_flush_buffer(file);
|
||||||
return res?res : MSVCRT_fputc(c, file);
|
if(!res)
|
||||||
|
res = MSVCRT_fputc(c, file);
|
||||||
|
MSVCRT__unlock_file(file);
|
||||||
|
return res;
|
||||||
} else {
|
} else {
|
||||||
unsigned char cc=c;
|
unsigned char cc=c;
|
||||||
int len;
|
int len;
|
||||||
/* set _cnt to 0 for unbuffered FILEs */
|
/* set _cnt to 0 for unbuffered FILEs */
|
||||||
file->_cnt = 0;
|
file->_cnt = 0;
|
||||||
len = MSVCRT__write(file->_file, &cc, 1);
|
len = MSVCRT__write(file->_file, &cc, 1);
|
||||||
if (len == 1) return c & 0xff;
|
if (len == 1) {
|
||||||
|
MSVCRT__unlock_file(file);
|
||||||
|
return c & 0xff;
|
||||||
|
}
|
||||||
file->_flag |= MSVCRT__IOERR;
|
file->_flag |= MSVCRT__IOERR;
|
||||||
|
MSVCRT__unlock_file(file);
|
||||||
return MSVCRT_EOF;
|
return MSVCRT_EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue