msvcrt: Added _fflush_nolock implementation.

Thanks to Piotr Caban for the test.
This commit is contained in:
Iván Matellanes 2014-10-20 21:03:16 +02:00 committed by Alexandre Julliard
parent c35f0161c0
commit 4bb80afedc
8 changed files with 45 additions and 9 deletions

View File

@ -799,7 +799,7 @@
@ cdecl _fcvt(double long ptr ptr) MSVCRT__fcvt
@ cdecl _fcvt_s(ptr long double long ptr ptr) MSVCRT__fcvt_s
@ cdecl _fdopen(long str) MSVCRT__fdopen
@ stub _fflush_nolock
@ cdecl _fflush_nolock(ptr) MSVCRT__fflush_nolock
@ cdecl _fgetchar() MSVCRT__fgetchar
@ stub _fgetwc_nolock
@ cdecl _fgetwchar() MSVCRT__fgetwchar

View File

@ -1147,7 +1147,7 @@
@ cdecl _fcvt(double long ptr ptr) MSVCRT__fcvt
@ cdecl _fcvt_s(ptr long double long ptr ptr) MSVCRT__fcvt_s
@ cdecl _fdopen(long str) MSVCRT__fdopen
@ stub _fflush_nolock
@ cdecl _fflush_nolock(ptr) MSVCRT__fflush_nolock
@ cdecl _fgetchar() MSVCRT__fgetchar
@ stub _fgetwc_nolock
@ cdecl _fgetwchar() MSVCRT__fgetwchar

View File

@ -466,7 +466,7 @@
@ cdecl _fcvt(double long ptr ptr) MSVCRT__fcvt
@ cdecl _fcvt_s(ptr long double long ptr ptr) MSVCRT__fcvt_s
@ cdecl _fdopen(long str) MSVCRT__fdopen
@ stub _fflush_nolock
@ cdecl _fflush_nolock(ptr) MSVCRT__fflush_nolock
@ cdecl _fgetchar() MSVCRT__fgetchar
@ stub _fgetwc_nolock
@ cdecl _fgetwchar() MSVCRT__fgetwchar

View File

@ -448,7 +448,7 @@
@ cdecl _fcvt(double long ptr ptr) MSVCRT__fcvt
@ cdecl _fcvt_s(ptr long double long ptr ptr) MSVCRT__fcvt_s
@ cdecl _fdopen(long str) MSVCRT__fdopen
@ stub _fflush_nolock
@ cdecl _fflush_nolock(ptr) MSVCRT__fflush_nolock
@ cdecl _fgetchar() MSVCRT__fgetchar
@ stub _fgetwc_nolock
@ cdecl _fgetwchar() MSVCRT__fgetwchar

View File

@ -121,6 +121,7 @@ static int (__cdecl *p_flsbuf)(int, FILE*);
static unsigned long (__cdecl *p_byteswap_ulong)(unsigned long);
static void** (__cdecl *p__pxcptinfoptrs)(void);
static void* (__cdecl *p__AdjustPointer)(void*, const void*);
static int (__cdecl *p_fflush_nolock)(FILE*);
/* make sure we use the correct errno */
#undef errno
@ -379,6 +380,7 @@ static BOOL init(void)
SET(p_byteswap_ulong, "_byteswap_ulong");
SET(p__pxcptinfoptrs, "__pxcptinfoptrs");
SET(p__AdjustPointer, "__AdjustPointer");
SET(p_fflush_nolock, "_fflush_nolock");
if (sizeof(void *) == 8)
{
SET(p_type_info_name_internal_method, "?_name_internal_method@type_info@@QEBAPEBDPEAU__type_info_node@@@Z");
@ -1207,16 +1209,22 @@ struct block_file_arg
FILE *write;
HANDLE init;
HANDLE finish;
int deadlock_test;
};
static DWORD WINAPI block_file(void *arg)
{
struct block_file_arg *files = arg;
int deadlock_test;
p_lock_file(files->read);
p_lock_file(files->write);
SetEvent(files->init);
WaitForSingleObject(files->finish, INFINITE);
Sleep(200);
deadlock_test = InterlockedIncrement(&files->deadlock_test);
ok(deadlock_test == 1, "deadlock_test = %d\n", deadlock_test);
p_unlock_file(files->read);
p_unlock_file(files->write);
return 0;
@ -1250,6 +1258,7 @@ static void test_nonblocking_file_access(void)
arg.write = filew;
arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
arg.deadlock_test = 0;
ok(arg.init != NULL, "CreateEventW failed\n");
ok(arg.finish != NULL, "CreateEventW failed\n");
thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
@ -1276,7 +1285,18 @@ static void test_nonblocking_file_access(void)
ret = p_flsbuf('a', filew);
ok(ret=='a', "_flsbuf(filew) returned %d\n", ret);
ret = p_fflush_nolock(filer);
ok(ret==0, "_fflush_nolock(filer) returned %d\n", ret);
ret = p_fflush_nolock(filew);
ok(ret==0, "_fflush_nolock(filew) returned %d\n", ret);
SetEvent(arg.finish);
ret = p_fflush_nolock(NULL);
ok(ret==0, "_fflush_nolock(NULL) returned %d\n", ret);
ret = InterlockedIncrement(&arg.deadlock_test);
ok(ret==2, "InterlockedIncrement returned %d\n", ret);
WaitForSingleObject(thread, INFINITE);
CloseHandle(arg.init);
CloseHandle(arg.finish);

View File

@ -918,25 +918,39 @@ int CDECL MSVCRT__flushall(void)
* fflush (MSVCRT.@)
*/
int CDECL MSVCRT_fflush(MSVCRT_FILE* file)
{
int ret;
if(!file) {
msvcrt_flush_all_buffers(MSVCRT__IOWRT);
ret = 0;
} else {
MSVCRT__lock_file(file);
ret = MSVCRT__fflush_nolock(file);
MSVCRT__unlock_file(file);
}
return ret;
}
/*********************************************************************
* _fflush_nolock (MSVCRT.@)
*/
int CDECL MSVCRT__fflush_nolock(MSVCRT_FILE* file)
{
if(!file) {
msvcrt_flush_all_buffers(MSVCRT__IOWRT);
} else if(file->_flag & MSVCRT__IOWRT) {
int res;
MSVCRT__lock_file(file);
res = msvcrt_flush_buffer(file);
if(!res && (file->_flag & MSVCRT__IOCOMMIT))
res = MSVCRT__commit(file->_file) ? MSVCRT_EOF : 0;
MSVCRT__unlock_file(file);
return res;
} else if(file->_flag & MSVCRT__IOREAD) {
MSVCRT__lock_file(file);
file->_cnt = 0;
file->_ptr = file->_base;
MSVCRT__unlock_file(file);
return 0;
}

View File

@ -931,6 +931,7 @@ MSVCRT_size_t __cdecl MSVCRT__fread_nolock(void*,MSVCRT_size_t,MSVCRT_size_t,MSV
MSVCRT_size_t __cdecl MSVCRT__fwrite_nolock(const void*,MSVCRT_size_t,MSVCRT_size_t,MSVCRT_FILE*);
int __cdecl MSVCRT_fclose(MSVCRT_FILE*);
int __cdecl MSVCRT__fclose_nolock(MSVCRT_FILE*);
int __cdecl MSVCRT__fflush_nolock(MSVCRT_FILE*);
void __cdecl MSVCRT_terminate(void);
MSVCRT_FILE* __cdecl MSVCRT__iob_func(void);
MSVCRT_clock_t __cdecl MSVCRT_clock(void);

View File

@ -130,6 +130,7 @@ int __cdecl _vsprintf_p_l(char*,size_t,const char*,_locale_t,__ms_va_list);
size_t __cdecl _fread_nolock(void*,size_t,size_t,FILE*);
size_t __cdecl _fwrite_nolock(const void*,size_t,size_t,FILE*);
int __cdecl _fclose_nolock(FILE*);
int __cdecl _fflush_nolock(FILE*);
int __cdecl _fseek_nolock(FILE*,__msvcrt_long,int);
int __cdecl _fseeki64_nolock(FILE*,__int64,int);
__msvcrt_long __cdecl _ftell_nolock(FILE*);