msvcrt: Move fread_s function to msvcrt.

This commit is contained in:
Piotr Caban 2013-03-28 12:57:14 +01:00 committed by Alexandre Julliard
parent 12b8c9671e
commit 280f8237b5
8 changed files with 61 additions and 57 deletions

View File

@ -447,59 +447,6 @@ unsigned __int64 CDECL _byteswap_uint64(unsigned __int64 i)
((i>>8)&0xFF000000) + ((i>>24)&0xFF0000) + ((i>>40)&0xFF00) + (i>>56);
}
/*********************************************************************
* fread_s (MSVCR100.@)
*/
size_t CDECL fread_s(void *buf, size_t buf_size, size_t elem_size, size_t count, FILE *stream)
{
size_t bytes_left, buf_pos;
TRACE("(%p %lu %lu %lu %p\n", buf, (unsigned long)buf_size,
(unsigned long)elem_size, (unsigned long)count, stream);
if(!CHECK_PMT(stream != NULL)) {
if(buf && buf_size)
memset(buf, 0, buf_size);
return 0;
}
if(!elem_size || !count) return 0;
if(!CHECK_PMT(buf != NULL)) return 0;
if(!CHECK_PMT(SIZE_MAX/count >= elem_size)) return 0;
bytes_left = elem_size*count;
buf_pos = 0;
while(bytes_left) {
if(stream->_cnt > 0) {
size_t size = bytes_left<stream->_cnt ? bytes_left : stream->_cnt;
if(!CHECK_PMT_ERR(size <= buf_size-buf_pos, ERANGE)) {
memset(buf, 0, buf_size);
return 0;
}
fread((char*)buf+buf_pos, 1, size, stream);
buf_pos += size;
bytes_left -= size;
}else {
int c = _filbuf(stream);
if(c == EOF)
break;
if(!CHECK_PMT_ERR(buf_size-buf_pos > 0, ERANGE)) {
memset(buf, 0, buf_size);
return 0;
}
((char*)buf)[buf_pos++] = c;
bytes_left--;
}
}
return buf_pos/elem_size;
}
/*********************************************************************
* _sprintf_p (MSVCR100.@)
*/

View File

@ -1670,7 +1670,7 @@
@ cdecl fputwc(long ptr) msvcrt.fputwc
@ cdecl fputws(wstr ptr) msvcrt.fputws
@ cdecl fread(ptr long long ptr) msvcrt.fread
@ cdecl fread_s(ptr long long long ptr)
@ cdecl fread_s(ptr long long long ptr) msvcrt.fread_s
@ cdecl free(ptr) msvcrt.free
@ cdecl freopen(str str ptr) msvcrt.freopen
@ cdecl freopen_s(ptr str str ptr) msvcrt.freopen_s

View File

@ -2033,7 +2033,7 @@
@ cdecl fputwc(long ptr) msvcrt.fputwc
@ cdecl fputws(wstr ptr) msvcrt.fputws
@ cdecl fread(ptr long long ptr) msvcrt.fread
@ cdecl fread_s(ptr long long long ptr) msvcr100.fread_s
@ cdecl fread_s(ptr long long long ptr) msvcrt.fread_s
@ cdecl free(ptr) msvcrt.free
@ cdecl freopen(str str ptr) msvcrt.freopen
@ cdecl freopen_s(ptr str str ptr) msvcrt.freopen_s

View File

@ -1323,7 +1323,7 @@
@ cdecl fputwc(long ptr) msvcrt.fputwc
@ cdecl fputws(wstr ptr) msvcrt.fputws
@ cdecl fread(ptr long long ptr) msvcrt.fread
@ cdecl fread_s(ptr long long long ptr) msvcr100.fread_s
@ cdecl fread_s(ptr long long long ptr) msvcrt.fread_s
@ cdecl free(ptr) msvcrt.free
@ cdecl freopen(str str ptr) msvcrt.freopen
@ cdecl freopen_s(ptr str str ptr) msvcrt.freopen_s

View File

@ -1324,7 +1324,7 @@
@ cdecl fputwc(long ptr) msvcrt.fputwc
@ cdecl fputws(wstr ptr) msvcrt.fputws
@ cdecl fread(ptr long long ptr) msvcrt.fread
@ cdecl fread_s(ptr long long long ptr) msvcr100.fread_s
@ cdecl fread_s(ptr long long long ptr) msvcrt.fread_s
@ cdecl free(ptr) msvcrt.free
@ cdecl freopen(str str ptr) msvcrt.freopen
@ cdecl freopen_s(ptr str str ptr) msvcrt.freopen_s

View File

@ -3686,6 +3686,57 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm
return read / size;
}
/* fread_s - not exported in native msvcrt */
MSVCRT_size_t CDECL fread_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);
if(!MSVCRT_CHECK_PMT(stream != NULL)) {
if(buf && buf_size)
memset(buf, 0, buf_size);
return 0;
}
if(!elem_size || !count) return 0;
if(!MSVCRT_CHECK_PMT(buf != NULL)) return 0;
if(!MSVCRT_CHECK_PMT(MSVCRT_SIZE_MAX/count >= elem_size)) return 0;
bytes_left = elem_size*count;
buf_pos = 0;
while(bytes_left) {
if(stream->_cnt > 0) {
size_t size = bytes_left<stream->_cnt ? bytes_left : stream->_cnt;
if(!MSVCRT_CHECK_PMT_ERR(size <= buf_size-buf_pos, MSVCRT_ERANGE)) {
memset(buf, 0, buf_size);
return 0;
}
MSVCRT_fread((char*)buf+buf_pos, 1, size, stream);
buf_pos += size;
bytes_left -= size;
}else {
int c = MSVCRT__filbuf(stream);
if(c == EOF)
break;
if(!MSVCRT_CHECK_PMT_ERR(buf_size-buf_pos > 0, MSVCRT_ERANGE)) {
memset(buf, 0, buf_size);
return 0;
}
((char*)buf)[buf_pos++] = c;
bytes_left--;
}
}
return buf_pos/elem_size;
}
/*********************************************************************
* _wfreopen (MSVCRT.@)
*

View File

@ -48,6 +48,11 @@
#define MSVCRT_I64_MIN (-MSVCRT_I64_MAX-1)
#define MSVCRT_UI64_MAX (((unsigned __int64)0xffffffff << 32) | 0xffffffff)
#define MSVCRT_MB_LEN_MAX 2
#ifdef _WIN64
#define MSVCRT_SIZE_MAX MSVCRT_UI64_MAX
#else
#define MSVCRT_SIZE_MAX MSVCRT_ULONG_MAX
#endif
#define MSVCRT__MAX_DRIVE 3
#define MSVCRT__MAX_DIR 256

View File

@ -1530,3 +1530,4 @@
@ cdecl _get_printf_count_output() MSVCRT__get_printf_count_output
@ cdecl _set_printf_count_output(long) MSVCRT__set_printf_count_output
@ cdecl _getptd()
@ cdecl fread_s(ptr long long long ptr)