Commit 758460fa authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Use type ranges definition from public header.

parent 4a4621f4
......@@ -22,6 +22,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include <direct.h>
#include "windef.h"
......@@ -1128,8 +1129,8 @@ do_error:
void CDECL MSVCRT__splitpath(const char *inpath, char *drv, char *dir,
char *fname, char *ext)
{
MSVCRT__splitpath_s(inpath, drv, drv?MSVCRT__MAX_DRIVE:0, dir, dir?MSVCRT__MAX_DIR:0,
fname, fname?MSVCRT__MAX_FNAME:0, ext, ext?MSVCRT__MAX_EXT:0);
MSVCRT__splitpath_s(inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0);
}
/******************************************************************
......@@ -1222,8 +1223,8 @@ do_error:
void CDECL MSVCRT__wsplitpath(const wchar_t *inpath, wchar_t *drv, wchar_t *dir,
wchar_t *fname, wchar_t *ext)
{
MSVCRT__wsplitpath_s(inpath, drv, drv?MSVCRT__MAX_DRIVE:0, dir, dir?MSVCRT__MAX_DIR:0,
fname, fname?MSVCRT__MAX_FNAME:0, ext, ext?MSVCRT__MAX_EXT:0);
MSVCRT__wsplitpath_s(inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0);
}
/*********************************************************************
......
......@@ -3830,7 +3830,7 @@ MSVCRT_wint_t CDECL MSVCRT__fgetwc_nolock(MSVCRT_FILE* file)
*p = (char)ch;
}
}else {
char mbs[MSVCRT_MB_LEN_MAX];
char mbs[MB_LEN_MAX];
int len = 0;
ch = MSVCRT__fgetc_nolock(file);
......@@ -4089,7 +4089,7 @@ MSVCRT_wint_t CDECL MSVCRT__fputwc_nolock(MSVCRT_wint_t wc, MSVCRT_FILE* file)
fdinfo = get_ioinfo_nolock(file->_file);
if((fdinfo->wxflag&WX_TEXT) && !(fdinfo->exflag&(EF_UTF8|EF_UTF16))) {
char buf[MSVCRT_MB_LEN_MAX];
char buf[MB_LEN_MAX];
int char_len;
char_len = MSVCRT_wctomb(buf, mwc);
......@@ -4406,7 +4406,7 @@ MSVCRT_size_t CDECL MSVCRT__fread_nolock_s(void *buf, MSVCRT_size_t buf_size, MS
}
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;
if(!MSVCRT_CHECK_PMT(SIZE_MAX/count >= elem_size)) return 0;
bytes_left = elem_size*count;
buf_pos = 0;
......@@ -5583,7 +5583,7 @@ MSVCRT_wint_t CDECL MSVCRT__ungetwc_nolock(MSVCRT_wint_t wc, MSVCRT_FILE * file)
return MSVCRT_WEOF;
}
}else {
char mbs[MSVCRT_MB_LEN_MAX];
char mbs[MB_LEN_MAX];
int len;
len = MSVCRT_wctomb(mbs, mwc);
......
......@@ -39,6 +39,7 @@
#include <stdio.h>
#include <fenv.h>
#include <fpieee.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
......@@ -4193,12 +4194,12 @@ int CDECL MSVCR120_ilogb(double x)
if (!e)
{
u.i <<= 12;
if (u.i == 0) return MSVCRT_FP_ILOGB0;
if (u.i == 0) return FP_ILOGB0;
/* subnormal x */
for (e = -0x3ff; u.i >> 63 == 0; e--, u.i <<= 1);
return e;
}
if (e == 0x7ff) return u.i << 12 ? MSVCRT_FP_ILOGBNAN : MSVCRT_INT_MAX;
if (e == 0x7ff) return u.i << 12 ? FP_ILOGBNAN : INT_MAX;
return e - 0x3ff;
}
......@@ -4215,12 +4216,12 @@ int CDECL MSVCR120_ilogbf(float x)
if (!e)
{
u.i <<= 9;
if (u.i == 0) return MSVCRT_FP_ILOGB0;
if (u.i == 0) return FP_ILOGB0;
/* subnormal x */
for (e = -0x7f; u.i >> 31 == 0; e--, u.i <<= 1);
return e;
}
if (e == 0xff) return u.i << 9 ? MSVCRT_FP_ILOGBNAN : MSVCRT_INT_MAX;
if (e == 0xff) return u.i << 9 ? FP_ILOGBNAN : INT_MAX;
return e - 0x7f;
}
......
......@@ -27,31 +27,8 @@
#include "windef.h"
#include "winbase.h"
#define MSVCRT_INT_MAX 0x7fffffff
#define MSVCRT_LONG_MAX 0x7fffffff
#define MSVCRT_LONG_MIN (-MSVCRT_LONG_MAX-1)
#define MSVCRT_ULONG_MAX 0xffffffff
#define MSVCRT_I64_MAX (((__int64)0x7fffffff << 32) | 0xffffffff)
#define MSVCRT_I64_MIN (-MSVCRT_I64_MAX-1)
#define MSVCRT_UI64_MAX (((unsigned __int64)0xffffffff << 32) | 0xffffffff)
#define MSVCRT_MB_LEN_MAX 5
#define MSVCRT_FLT_MAX_10_EXP 38
#define MSVCRT_FLT_MIN_10_EXP (-37)
#define MSVCRT_DBL_MAX_10_EXP 308
#define MSVCRT_DBL_MIN_10_EXP (-307)
#define DBL80_MAX_10_EXP 4932
#define DBL80_MIN_10_EXP -4951
#define MSVCRT_DBL_DIG 15
#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
#define MSVCRT__MAX_FNAME 256
#define MSVCRT__MAX_EXT 256
typedef unsigned char MSVCRT_bool;
typedef wint_t MSVCRT_wint_t;
......@@ -1077,9 +1054,6 @@ printf_arg arg_clbk_positional(void*, int, int, __ms_va_list*) DECLSPEC_HIDDEN;
#define MSVCRT__OVERFLOW 3
#define MSVCRT__UNDERFLOW 4
#define MSVCRT_FP_ILOGB0 (-MSVCRT_INT_MAX - 1)
#define MSVCRT_FP_ILOGBNAN MSVCRT_INT_MAX
typedef struct
{
float f;
......
......@@ -111,7 +111,7 @@ static inline int FUNC_NAME(pf_fill)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ct
static inline int wcstombs_len(char *mbstr, const wchar_t *wcstr,
int len, _locale_t locale)
{
char buf[MSVCRT_MB_LEN_MAX];
char buf[MB_LEN_MAX];
int i, r, mblen = 0;
for(i=0; i<len; i++) {
......
......@@ -28,6 +28,7 @@
#include <limits.h>
#include <locale.h>
#include <errno.h>
#include <float.h>
#include "msvcrt.h"
#include "bnum.h"
#include "winnls.h"
......@@ -552,7 +553,7 @@ int fpnum_ldouble(struct fpnum *fp, MSVCRT__LDOUBLE *d)
/* round mantissa */
if (fp->mod == FP_ROUND_UP || (fp->mod == FP_ROUND_EVEN && fp->m & 1))
{
if (fp->m == MSVCRT_UI64_MAX)
if (fp->m == UI64_MAX)
{
fp->m = (ULONGLONG)1 << (LDBL_MANT_BITS - 1);
fp->exp++;
......@@ -616,7 +617,7 @@ static struct fpnum fpnum_parse16(wchar_t get(void *ctx), void unget(void *ctx),
int val, exp = 0;
nch = get(ctx);
while(m < MSVCRT_UI64_MAX/16)
while(m < UI64_MAX/16)
{
val = hex2int(nch);
if (val == -1) break;
......@@ -652,7 +653,7 @@ static struct fpnum fpnum_parse16(wchar_t get(void *ctx), void unget(void *ctx),
return fpnum(0, 0, 0, 0);
}
while(m <= MSVCRT_UI64_MAX/16)
while(m <= UI64_MAX/16)
{
val = hex2int(nch);
if (val == -1) break;
......@@ -726,13 +727,13 @@ static struct fpnum fpnum_parse16(wchar_t get(void *ctx), void unget(void *ctx),
/* Return FALSE on overflow */
static inline BOOL bnum_to_mant(struct bnum *b, ULONGLONG *m)
{
if(MSVCRT_UI64_MAX / LIMB_MAX / LIMB_MAX < b->data[bnum_idx(b, b->e-1)]) return FALSE;
if(UI64_MAX / LIMB_MAX / LIMB_MAX < b->data[bnum_idx(b, b->e-1)]) return FALSE;
*m = (ULONGLONG)b->data[bnum_idx(b, b->e-1)] * LIMB_MAX * LIMB_MAX;
if(b->b == b->e-1) return TRUE;
if(MSVCRT_UI64_MAX - *m < (ULONGLONG)b->data[bnum_idx(b, b->e-2)] * LIMB_MAX) return FALSE;
if(UI64_MAX - *m < (ULONGLONG)b->data[bnum_idx(b, b->e-2)] * LIMB_MAX) return FALSE;
*m += (ULONGLONG)b->data[bnum_idx(b, b->e-2)] * LIMB_MAX;
if(b->b == b->e-2) return TRUE;
if(MSVCRT_UI64_MAX - *m < b->data[bnum_idx(b, b->e-3)]) return FALSE;
if(UI64_MAX - *m < b->data[bnum_idx(b, b->e-3)]) return FALSE;
*m += b->data[bnum_idx(b, b->e-3)];
return TRUE;
}
......@@ -928,11 +929,11 @@ static struct fpnum fpnum_parse_bnum(wchar_t (*get)(void *ctx), void (*unget)(vo
if(off < 0) off += LIMB_DIGITS;
if(off) bnum_mult(b, p10s[off]);
if(dp-1 > (ldouble ? DBL80_MAX_10_EXP : MSVCRT_DBL_MAX_10_EXP))
if(dp-1 > (ldouble ? DBL80_MAX_10_EXP : DBL_MAX_10_EXP))
return fpnum(sign, INT_MAX, 1, FP_ROUND_ZERO);
/* Count part of exponent stored in denormalized mantissa. */
/* Increase exponent range to handle subnormals. */
if(dp-1 < (ldouble ? DBL80_MIN_10_EXP : MSVCRT_DBL_MIN_10_EXP-MSVCRT_DBL_DIG-18))
if(dp-1 < (ldouble ? DBL80_MIN_10_EXP : DBL_MIN_10_EXP-DBL_DIG-18))
return fpnum(sign, INT_MIN, 1, FP_ROUND_ZERO);
while(dp > 3*LIMB_DIGITS) {
......@@ -1577,11 +1578,11 @@ __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, _loca
nptr++;
if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
ret = MSVCRT_I64_MAX;
if(!negative && (ret>I64_MAX/base || ret*base>I64_MAX-v)) {
ret = I64_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
ret = MSVCRT_I64_MIN;
} else if(negative && (ret<I64_MIN/base || ret*base<I64_MIN-v)) {
ret = I64_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else
ret = ret*base + v;
......@@ -1676,11 +1677,11 @@ MSVCRT_long CDECL MSVCRT__atol_l(const char *str, _locale_t locale)
{
__int64 ret = MSVCRT_strtoi64_l(str, NULL, 10, locale);
if(ret > MSVCRT_LONG_MAX) {
ret = MSVCRT_LONG_MAX;
if(ret > LONG_MAX) {
ret = LONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else if(ret < MSVCRT_LONG_MIN) {
ret = MSVCRT_LONG_MIN;
} else if(ret < LONG_MIN) {
ret = LONG_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
return ret;
......@@ -1726,11 +1727,11 @@ MSVCRT_long CDECL MSVCRT__strtol_l(const char* nptr,
{
__int64 ret = MSVCRT_strtoi64_l(nptr, end, base, locale);
if(ret > MSVCRT_LONG_MAX) {
ret = MSVCRT_LONG_MAX;
if(ret > LONG_MAX) {
ret = LONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else if(ret < MSVCRT_LONG_MIN) {
ret = MSVCRT_LONG_MIN;
} else if(ret < LONG_MIN) {
ret = LONG_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
......@@ -1752,10 +1753,10 @@ MSVCRT_ulong CDECL MSVCRT_strtoul_l(const char* nptr, char** end, int base, _loc
{
__int64 ret = MSVCRT_strtoi64_l(nptr, end, base, locale);
if(ret > MSVCRT_ULONG_MAX) {
ret = MSVCRT_ULONG_MAX;
if(ret > ULONG_MAX) {
ret = ULONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
}else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
}else if(ret < -(__int64)ULONG_MAX) {
ret = 1;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
......@@ -1826,8 +1827,8 @@ unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int b
nptr++;
if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
ret = MSVCRT_UI64_MAX;
if(ret>UI64_MAX/base || ret*base>UI64_MAX-v) {
ret = UI64_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else
ret = ret*base + v;
......@@ -2015,7 +2016,7 @@ int CDECL MSVCRT__itoa_s(int value, char *str, MSVCRT_size_t size, int radix)
*/
char* CDECL MSVCRT__itoa(int value, char *str, int radix)
{
return ltoa_helper(value, str, MSVCRT_SIZE_MAX, radix) ? NULL : str;
return ltoa_helper(value, str, SIZE_MAX, radix) ? NULL : str;
}
/*********************************************************************
......
......@@ -955,7 +955,7 @@ char ** CDECL __p__tzname(void)
#define STRFTIME_TD(td, name) td->wstr.names.name
#endif
#define strftime_str(a,b,c,d) strftime_nstr(a,b,c,d,MSVCRT_SIZE_MAX)
#define strftime_str(a,b,c,d) strftime_nstr(a,b,c,d,SIZE_MAX)
static inline BOOL strftime_nstr(STRFTIME_CHAR *str, MSVCRT_size_t *pos,
MSVCRT_size_t max, const STRFTIME_CHAR *src, MSVCRT_size_t len)
{
......@@ -1142,7 +1142,7 @@ static inline BOOL strftime_format(STRFTIME_CHAR *str, MSVCRT_size_t *pos, MSVCR
}
ret = strftime_nstr(str, pos, max,
mstm->tm_hour < 12 ? STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm),
(*format == 't' && count == 1) ? 1 : MSVCRT_SIZE_MAX);
(*format == 't' && count == 1) ? 1 : SIZE_MAX);
break;
default:
ret = strftime_nstr(str, pos, max, format, count);
......
......@@ -2016,7 +2016,7 @@ int CDECL MSVCRT__wctomb_l(char *dst, wchar_t ch, _locale_t locale)
{
int len;
MSVCRT__wctomb_s_l(&len, dst, dst ? MSVCRT_MB_LEN_MAX : 0, ch, locale);
MSVCRT__wctomb_s_l(&len, dst, dst ? MB_LEN_MAX : 0, ch, locale);
return len;
}
......@@ -2556,11 +2556,11 @@ __int64 CDECL MSVCRT__wcstoi64_l(const wchar_t *nptr,
nptr++;
empty = FALSE;
if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
ret = MSVCRT_I64_MAX;
if(!negative && (ret>I64_MAX/base || ret*base>I64_MAX-v)) {
ret = I64_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
ret = MSVCRT_I64_MIN;
} else if(negative && (ret<I64_MIN/base || ret*base<I64_MIN-v)) {
ret = I64_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else
ret = ret*base + v;
......@@ -2589,11 +2589,11 @@ MSVCRT_long CDECL MSVCRT__wcstol_l(const wchar_t *s,
{
__int64 ret = MSVCRT__wcstoi64_l(s, end, base, locale);
if(ret > MSVCRT_LONG_MAX) {
ret = MSVCRT_LONG_MAX;
if(ret > LONG_MAX) {
ret = LONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
}else if(ret < MSVCRT_LONG_MIN) {
ret = MSVCRT_LONG_MIN;
}else if(ret < LONG_MIN) {
ret = LONG_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
return ret;
......@@ -2640,11 +2640,11 @@ MSVCRT_long __cdecl MSVCRT__wtol_l(const wchar_t *str, _locale_t locale)
{
__int64 ret = MSVCRT__wcstoi64_l(str, NULL, 10, locale);
if(ret > MSVCRT_LONG_MAX) {
ret = MSVCRT_LONG_MAX;
if(ret > LONG_MAX) {
ret = LONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else if(ret < MSVCRT_LONG_MIN) {
ret = MSVCRT_LONG_MIN;
} else if(ret < LONG_MIN) {
ret = LONG_MIN;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
return ret;
......@@ -2726,8 +2726,8 @@ unsigned __int64 CDECL MSVCRT__wcstoui64_l(const wchar_t *nptr,
nptr++;
empty = FALSE;
if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
ret = MSVCRT_UI64_MAX;
if(ret>UI64_MAX/base || ret*base>UI64_MAX-v) {
ret = UI64_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
} else
ret = ret*base + v;
......@@ -2756,10 +2756,10 @@ MSVCRT_ulong __cdecl MSVCRT__wcstoul_l(const wchar_t *s,
{
__int64 ret = MSVCRT__wcstoi64_l(s, end, base, locale);
if(ret > MSVCRT_ULONG_MAX) {
ret = MSVCRT_ULONG_MAX;
if(ret > ULONG_MAX) {
ret = ULONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
}else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
}else if(ret < -(__int64)ULONG_MAX) {
ret = 1;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
......
......@@ -219,6 +219,10 @@ static const union {
#define FP_SUBNORMAL -2
#define FP_ZERO 0
#define _C2 1
#define FP_ILOGB0 (-0x7fffffff - _C2)
#define FP_ILOGBNAN 0x7fffffff
_ACRTIMP short __cdecl _dclass(double);
_ACRTIMP short __cdecl _fdclass(float);
_ACRTIMP int __cdecl _dsign(double);
......
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