diff --git a/dlls/msvcr100/msvcr100.c b/dlls/msvcr100/msvcr100.c index 3a0a2056d47..2735d17f493 100644 --- a/dlls/msvcr100/msvcr100.c +++ b/dlls/msvcr100/msvcr100.c @@ -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_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.@) */ diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index efba85aa2b6..af0008263b4 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -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 diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index 3718eae2e0d..a80cc6e9adc 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -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 diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index 0d6b8f825f6..d8f361fd59d 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -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 diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 158c9f54ae8..7916839ea68 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -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 diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 28dd132a781..c8863b3ffc7 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -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_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.@) * diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index 69ad7a7f21f..c688dea46ad 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -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 diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index a569ea2376a..edef6156859 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -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)