Commit bcbd83d1 authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcrt: Added _fread_nolock_s implementation.

parent e4f9f537
......@@ -835,7 +835,7 @@
@ cdecl _fputwc_nolock(long ptr) MSVCRT__fputwc_nolock
@ cdecl _fputwchar(long) MSVCRT__fputwchar
@ cdecl _fread_nolock(ptr long long ptr) MSVCRT__fread_nolock
@ stub _fread_nolock_s
@ cdecl _fread_nolock_s(ptr long long long ptr) MSVCRT__fread_nolock_s
@ cdecl _free_locale(ptr) MSVCRT__free_locale
@ stub _freea
@ stub _freea_s
......
......@@ -140,6 +140,8 @@ static int (__cdecl *p_wmemmove_s)(wchar_t *dest, size_t numberOfElements, const
static FILE* (__cdecl *p_fopen)(const char*,const char*);
static int (__cdecl *p_fclose)(FILE*);
static size_t (__cdecl *p_fread_s)(void*,size_t,size_t,size_t,FILE*);
static void (__cdecl *p_lock_file)(FILE*);
static void (__cdecl *p_unlock_file)(FILE*);
static void* (__cdecl *p__aligned_offset_malloc)(size_t, size_t, size_t);
static void (__cdecl *p__aligned_free)(void*);
static size_t (__cdecl *p__aligned_msize)(void*, size_t, size_t);
......@@ -178,6 +180,8 @@ static BOOL init(void)
SET(p_fopen, "fopen");
SET(p_fclose, "fclose");
SET(p_fread_s, "fread_s");
SET(p_lock_file, "_lock_file");
SET(p_unlock_file, "_unlock_file");
SET(p__aligned_offset_malloc, "_aligned_offset_malloc");
SET(p__aligned_free, "_aligned_free");
SET(p__aligned_msize, "_aligned_msize");
......@@ -357,11 +361,30 @@ static void test_wmemmove_s(void)
"Cannot reset invalid parameter handler\n");
}
struct block_file_arg
{
FILE *test_file;
HANDLE init;
HANDLE finish;
};
static DWORD WINAPI block_file(void *arg)
{
struct block_file_arg *files = arg;
p_lock_file(files->test_file);
SetEvent(files->init);
WaitForSingleObject(files->finish, INFINITE);
p_unlock_file(files->test_file);
return 0;
}
static void test_fread_s(void)
{
static const char test_file[] = "fread_s.tst";
int ret;
char buf[10];
HANDLE thread;
struct block_file_arg arg;
FILE *f = fopen(test_file, "w");
if(!f) {
......@@ -382,6 +405,12 @@ static void test_fread_s(void)
CHECK_CALLED(invalid_parameter_handler);
f = p_fopen(test_file, "r");
arg.test_file = f;
arg.init = CreateEventW(NULL, FALSE, FALSE, NULL);
arg.finish = CreateEventW(NULL, FALSE, FALSE, NULL);
thread = CreateThread(NULL, 0, block_file, (void*)&arg, 0, NULL);
WaitForSingleObject(arg.init, INFINITE);
errno = 0xdeadbeef;
ret = p_fread_s(NULL, sizeof(buf), 0, 1, f);
ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
......@@ -390,6 +419,9 @@ static void test_fread_s(void)
ok(ret == 0, "fread_s returned %d, expected 0\n", ret);
ok(errno == 0xdeadbeef, "errno = %d, expected 0xdeadbeef\n", errno);
SetEvent(arg.finish);
WaitForSingleObject(thread, INFINITE);
SET_EXPECT(invalid_parameter_handler);
errno = 0xdeadbeef;
ret = p_fread_s(NULL, sizeof(buf), 1, 1, f);
......@@ -426,6 +458,9 @@ static void test_fread_s(void)
ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
"Cannot reset invalid parameter handler\n");
CloseHandle(arg.init);
CloseHandle(arg.finish);
CloseHandle(thread);
unlink(test_file);
}
......
......@@ -1183,7 +1183,7 @@
@ cdecl _fputwc_nolock(long ptr) MSVCRT__fputwc_nolock
@ cdecl _fputwchar(long) MSVCRT__fputwchar
@ cdecl _fread_nolock(ptr long long ptr) MSVCRT__fread_nolock
@ stub _fread_nolock_s
@ cdecl _fread_nolock_s(ptr long long long ptr) MSVCRT__fread_nolock_s
@ cdecl _free_locale(ptr) MSVCRT__free_locale
@ stub _freea
@ stub _freea_s
......
......@@ -1181,7 +1181,7 @@
@ cdecl _fputwc_nolock(long ptr) MSVCRT__fputwc_nolock
@ cdecl _fputwchar(long) MSVCRT__fputwchar
@ cdecl _fread_nolock(ptr long long ptr) MSVCRT__fread_nolock
@ stub _fread_nolock_s
@ cdecl _fread_nolock_s(ptr long long long ptr) MSVCRT__fread_nolock_s
@ cdecl _free_locale(ptr) MSVCRT__free_locale
@ stub _freea
@ stub _freea_s
......
......@@ -502,7 +502,7 @@
@ cdecl _fputwc_nolock(long ptr) MSVCRT__fputwc_nolock
@ cdecl _fputwchar(long) MSVCRT__fputwchar
@ cdecl _fread_nolock(ptr long long ptr) MSVCRT__fread_nolock
@ stub _fread_nolock_s
@ cdecl _fread_nolock_s(ptr long long long ptr) MSVCRT__fread_nolock_s
@ cdecl _free_locale(ptr) MSVCRT__free_locale
@ stub _freea
@ stub _freea_s
......
......@@ -484,7 +484,7 @@
@ cdecl _fputwc_nolock(long ptr) MSVCRT__fputwc_nolock
@ cdecl _fputwchar(long) MSVCRT__fputwchar
@ cdecl _fread_nolock(ptr long long ptr) MSVCRT__fread_nolock
@ stub _fread_nolock_s
@ cdecl _fread_nolock_s(ptr long long long ptr) MSVCRT__fread_nolock_s
@ cdecl _free_locale(ptr) MSVCRT__free_locale
@ stub _freea
@ stub _freea_s
......
......@@ -4130,9 +4130,31 @@ MSVCRT_size_t CDECL MSVCRT__fread_nolock(void *ptr, MSVCRT_size_t size, MSVCRT_s
MSVCRT_size_t CDECL MSVCRT_fread_s(void *buf, MSVCRT_size_t buf_size, MSVCRT_size_t elem_size,
MSVCRT_size_t count, MSVCRT_FILE *stream)
{
MSVCRT_size_t ret;
if(!MSVCRT_CHECK_PMT(stream != NULL)) {
if(buf && buf_size)
memset(buf, 0, buf_size);
return 0;
}
if(!elem_size || !count) return 0;
MSVCRT__lock_file(stream);
ret = MSVCRT__fread_nolock_s(buf, buf_size, elem_size, count, stream);
MSVCRT__unlock_file(stream);
return ret;
}
/*********************************************************************
* _fread_nolock_s (MSVCR80.@)
*/
MSVCRT_size_t CDECL MSVCRT__fread_nolock_s(void *buf, MSVCRT_size_t buf_size, MSVCRT_size_t elem_size,
MSVCRT_size_t count, MSVCRT_FILE *stream)
{
size_t bytes_left, buf_pos;
TRACE("(%p %lu %lu %lu %p\n", buf, buf_size, elem_size, count, stream);
TRACE("(%p %lu %lu %lu %p)\n", buf, buf_size, elem_size, count, stream);
if(!MSVCRT_CHECK_PMT(stream != NULL)) {
if(buf && buf_size)
......@@ -4154,7 +4176,7 @@ MSVCRT_size_t CDECL MSVCRT_fread_s(void *buf, MSVCRT_size_t buf_size, MSVCRT_siz
return 0;
}
MSVCRT_fread((char*)buf+buf_pos, 1, size, stream);
MSVCRT__fread_nolock((char*)buf+buf_pos, 1, size, stream);
buf_pos += size;
bytes_left -= size;
}else {
......
......@@ -934,6 +934,7 @@ MSVCRT_ulong* __cdecl MSVCRT___doserrno(void);
int* __cdecl MSVCRT__errno(void);
char* __cdecl MSVCRT_getenv(const char*);
MSVCRT_size_t __cdecl MSVCRT__fread_nolock(void*,MSVCRT_size_t,MSVCRT_size_t,MSVCRT_FILE*);
MSVCRT_size_t __cdecl MSVCRT__fread_nolock_s(void*,MSVCRT_size_t,MSVCRT_size_t,MSVCRT_size_t,MSVCRT_FILE*);
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*);
......
......@@ -128,6 +128,7 @@ int __cdecl _vsnprintf_s(char*,size_t,size_t,const char*,__ms_va_list);
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 _fread_nolock_s(void*,size_t,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*);
......@@ -156,6 +157,7 @@ int __cdecl fprintf_s(FILE*,const char*,...);
int __cdecl fputc(int,FILE*);
int __cdecl fputs(const char*,FILE*);
size_t __cdecl fread(void*,size_t,size_t,FILE*);
size_t __cdecl fread_s(void*,size_t,size_t,size_t,FILE*);
FILE* __cdecl freopen(const char*,const char*,FILE*);
int __cdecl fscanf(FILE*,const char*,...);
int __cdecl fscanf_s(FILE*,const char*,...);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment