diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/src/cruntime | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/src/cruntime')
-rw-r--r-- | src/pal/src/cruntime/lstr.cpp | 210 | ||||
-rw-r--r-- | src/pal/src/cruntime/math.cpp | 367 | ||||
-rw-r--r-- | src/pal/src/cruntime/mbstring.cpp | 54 | ||||
-rw-r--r-- | src/pal/src/cruntime/path.cpp | 482 | ||||
-rw-r--r-- | src/pal/src/cruntime/printf.cpp | 202 | ||||
-rw-r--r-- | src/pal/src/cruntime/string.cpp | 55 | ||||
-rw-r--r-- | src/pal/src/cruntime/wchar.cpp | 211 |
7 files changed, 367 insertions, 1214 deletions
diff --git a/src/pal/src/cruntime/lstr.cpp b/src/pal/src/cruntime/lstr.cpp index 2267d8491b..4502b025aa 100644 --- a/src/pal/src/cruntime/lstr.cpp +++ b/src/pal/src/cruntime/lstr.cpp @@ -24,141 +24,6 @@ Abstract: SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/*++ -Function: - lstrcatW - -The lstrcat function appends one string to another. - -Parameters - -lpString1 [in/out] Pointer to a null-terminated string. The buffer must be large - enough to contain both strings. -lpString2 [in] Pointer to the null-terminated string to be appended to the - string specified in the lpString1 parameter. - -Return Values - -If the function succeeds, the return value is a pointer to the buffer. -If the function fails, the return value is NULL. - ---*/ -LPWSTR -PALAPI -lstrcatW( - IN OUT LPWSTR lpString1, - IN LPCWSTR lpString2) -{ - LPWSTR lpStart = lpString1; - - PERF_ENTRY(lstrcatW); - ENTRY("lstrcatW (lpString1=%p (%S), lpString2=%p (%S))\n", - lpString1?lpString1:W16_NULLSTRING, - lpString1?lpString1:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING); - - if (lpString1 == NULL) - { - ERROR("invalid lpString1 argument\n"); - LOGEXIT("lstrcatW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcatW); - return NULL; - } - - if (lpString2 == NULL) - { - ERROR("invalid lpString2 argument\n"); - LOGEXIT("lstrcatW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcatW); - return NULL; - } - - /* find end of source string */ - while (*lpString1) - { - lpString1++; - } - - /* concatenate new string */ - while(*lpString2) - { - *lpString1++ = *lpString2++; - } - - /* add terminating null */ - *lpString1 = '\0'; - - LOGEXIT("lstrcatW returning LPWSTR %p (%S)\n", lpStart, lpStart); - PERF_EXIT(lstrcatW); - return lpStart; -} - - -/*++ -Function: - lstrcpyW - -The lstrcpy function copies a string to a buffer. - -To copy a specified number of characters, use the lstrcpyn function. - -Parameters - -lpString1 [out] Pointer to a buffer to receive the contents of the string pointed - to by the lpString2 parameter. The buffer must be large enough to - contain the string, including the terminating null character. - -lpString2 [in] Pointer to the null-terminated string to be copied. - -Return Values - -If the function succeeds, the return value is a pointer to the buffer. -If the function fails, the return value is NULL. - ---*/ -LPWSTR -PALAPI -lstrcpyW( - OUT LPWSTR lpString1, - IN LPCWSTR lpString2) -{ - LPWSTR lpStart = lpString1; - - PERF_ENTRY(lstrcpyW); - ENTRY("lstrcpyW (lpString1=%p, lpString2=%p (%S))\n", - lpString1?lpString1:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING); - - if (lpString1 == NULL) - { - ERROR("invalid lpString1 argument\n"); - LOGEXIT("lstrcpyW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcpyW); - return NULL; - } - - if (lpString2 == NULL) - { - ERROR("invalid lpString2 argument\n"); - LOGEXIT("lstrcpyW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcpyW); - return NULL; - } - - /* copy source string to destination string */ - while(*lpString2) - { - *lpString1++ = *lpString2++; - } - - /* add terminating null */ - *lpString1 = '\0'; - - LOGEXIT("lstrcpyW returning LPWSTR %p (%S)\n", lpStart, lpStart); - PERF_EXIT(lstrcpyW); - return lpStart; -} - - /*++ Function: lstrlenA @@ -239,78 +104,3 @@ lstrlenW( PERF_EXIT(lstrlenW); return nChar; } - - -/*++ -Function: - lstrcpynW - -The lstrcpyn function copies a specified number of characters from a -source string into a buffer. - -Parameters - -lpString1 [out] Pointer to a buffer into which the function copies characters. - The buffer must be large enough to contain the number of TCHARs - specified by iMaxLength, including room for a terminating null character. -lpString2 [in] Pointer to a null-terminated string from which the function copies - characters. -iMaxLength [in] Specifies the number of TCHARs to be copied from the string pointed - to by lpString2 into the buffer pointed to by lpString1, including a - terminating null character. - -Return Values - -If the function succeeds, the return value is a pointer to the buffer. -If the function fails, the return value is NULL. - ---*/ -LPWSTR -PALAPI -lstrcpynW( - OUT LPWSTR lpString1, - IN LPCWSTR lpString2, - IN int iMaxLength) -{ - LPWSTR lpStart = lpString1; - - PERF_ENTRY(lstrcpynW); - ENTRY("lstrcpynW (lpString1=%p, lpString2=%p (%S), iMaxLength=%d)\n", - lpString1?lpString1:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING, lpString2?lpString2:W16_NULLSTRING, iMaxLength); - - if (lpString1 == NULL) - { - ERROR("invalid lpString1 argument\n"); - LOGEXIT("lstrcpynW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcpynW); - return NULL; - } - - if (lpString2 == NULL) - { - ERROR("invalid lpString2 argument\n"); - LOGEXIT("lstrcpynW returning LPWSTR NULL\n"); - PERF_EXIT(lstrcpynW); - return NULL; - } - - /* copy source string to destination string */ - while(iMaxLength > 1 && *lpString2) - { - *lpString1++ = *lpString2++; - iMaxLength--; - } - - /* add terminating null */ - if (iMaxLength > 0) - { - *lpString1 = '\0'; - } - - LOGEXIT("lstrcpynW returning LPWSTR %p (%S)\n", lpStart, lpStart); - PERF_EXIT(lstrcpynW); - return lpStart; - -} - - diff --git a/src/pal/src/cruntime/math.cpp b/src/pal/src/cruntime/math.cpp index 7075fd60f9..08f4192998 100644 --- a/src/pal/src/cruntime/math.cpp +++ b/src/pal/src/cruntime/math.cpp @@ -35,6 +35,12 @@ Abstract: #define IS_DBL_NEGZERO(x) (((*((INT64*)((void*)&x))) & I64(0xFFFFFFFFFFFFFFFF)) == I64(0x8000000000000000)) +#define PAL_NAN_FLT sqrtf(-1.0f) +#define PAL_POSINF_FLT -logf(0.0f) +#define PAL_NEGINF_FLT logf(0.0f) + +#define IS_FLT_NEGZERO(x) (((*((INT32*)((void*)&x))) & 0xFFFFFFFF) == 0x80000000) + SET_DEFAULT_DEBUG_CHANNEL(CRT); /*++ @@ -422,3 +428,364 @@ PALIMPORT double __cdecl PAL_pow(double x, double y) PERF_EXIT(pow); return ret; } + +/*++ +Function: + _finitef + +Determines whether given single-precision floating point value is finite. + +Return Value + +_finitef returns a nonzero value (TRUE) if its argument x is not +infinite, that is, if -INF < x < +INF. It returns 0 (FALSE) if the +argument is infinite or a NaN. + +Parameter + +x Single-precision floating-point value + +--*/ +int __cdecl _finitef(float x) +{ + int ret; + PERF_ENTRY(_finitef); + ENTRY("_finitef (x=%f)\n", x); + +#if defined(_IA64_) && defined (_HPUX_) + ret = !isnan(x) && (x != PAL_POSINF_FLT) && (x != PAL_NEGINF_FLT); +#else + ret = isfinite(x); +#endif + + LOGEXIT("_finitef returns int %d\n", ret); + PERF_EXIT(_finitef); + return ret; +} + +/*++ +Function: + _isnanf + +See MSDN doc +--*/ +int __cdecl _isnanf(float x) +{ + int ret; + PERF_ENTRY(_isnanf); + ENTRY("_isnanf (x=%f)\n", x); + + ret = isnan(x); + + LOGEXIT("_isnanf returns int %d\n", ret); + PERF_EXIT(_isnanf); + return ret; +} + +/*++ +Function: + _copysignf + +See MSDN doc +--*/ +float __cdecl _copysignf(float x, float y) +{ + float ret; + PERF_ENTRY(_copysignf); + ENTRY("_copysignf (x=%f, y=%f)\n", x, y); + + ret = copysign(x, y); + + LOGEXIT("_copysignf returns float %f\n", ret); + PERF_EXIT(_copysignf); + return ret; +} + +/*++ +Function: + acosf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_acosf(float x) +{ + float ret; + PERF_ENTRY(acosf); + ENTRY("acosf (x=%f)\n", x); + +#if !HAVE_COMPATIBLE_ACOS + errno = 0; +#endif // HAVE_COMPATIBLE_ACOS + + ret = acosf(x); + +#if !HAVE_COMPATIBLE_ACOS + if (errno == EDOM) + { + ret = PAL_NAN_FLT; // NaN + } +#endif // HAVE_COMPATIBLE_ACOS + + LOGEXIT("acosf returns float %f\n", ret); + PERF_EXIT(acosf); + return ret; +} + +/*++ +Function: + asinf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_asinf(float x) +{ + float ret; + PERF_ENTRY(asinf); + ENTRY("asinf (x=%f)\n", x); + +#if !HAVE_COMPATIBLE_ASIN + errno = 0; +#endif // HAVE_COMPATIBLE_ASIN + + ret = asinf(x); + +#if !HAVE_COMPATIBLE_ASIN + if (errno == EDOM) + { + ret = PAL_NAN_FLT; // NaN + } +#endif // HAVE_COMPATIBLE_ASIN + + LOGEXIT("asinf returns float %f\n", ret); + PERF_EXIT(asinf); + return ret; +} + +/*++ +Function: + atan2f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_atan2f(float y, float x) +{ + float ret; + PERF_ENTRY(atan2f); + ENTRY("atan2f (y=%f, x=%f)\n", y, x); + +#if !HAVE_COMPATIBLE_ATAN2 + errno = 0; +#endif // !HAVE_COMPATIBLE_ATAN2 + + ret = atan2f(y, x); + +#if !HAVE_COMPATIBLE_ATAN2 + if ((errno == EDOM) && (x == 0.0f) && (y == 0.0f)) + { + const float sign_x = copysign(1.0f, x); + const float sign_y = copysign(1.0f, y); + + if (sign_x > 0) + { + ret = copysign(0.0f, sign_y); + } + else + { + ret = copysign(atan2f(0.0f, -1.0f), sign_y); + } + } +#endif // !HAVE_COMPATIBLE_ATAN2 + + LOGEXIT("atan2f returns float %f\n", ret); + PERF_EXIT(atan2f); + return ret; +} + +/*++ +Function: + expf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_expf(float x) +{ + float ret; + PERF_ENTRY(expf); + ENTRY("expf (x=%f)\n", x); + +#if !HAVE_COMPATIBLE_EXP + if (x == 1.0f) + { + ret = M_E; + } + else + { +#endif // HAVE_COMPATIBLE_EXP + + ret = expf(x); + +#if !HAVE_COMPATIBLE_EXP + } +#endif // HAVE_COMPATIBLE_EXP + + LOGEXIT("expf returns float %f\n", ret); + PERF_EXIT(expf); + return ret; +} + +/*++ +Function: + logf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_logf(float x) +{ + float ret; + PERF_ENTRY(logf); + ENTRY("logf (x=%f)\n", x); + +#if !HAVE_COMPATIBLE_LOG + errno = 0; +#endif // !HAVE_COMPATIBLE_LOG + + ret = logf(x); + +#if !HAVE_COMPATIBLE_LOG + if ((errno == EDOM) && (x < 0)) + { + ret = PAL_NAN_FLT; // NaN + } +#endif // !HAVE_COMPATIBLE_LOG + + LOGEXIT("logf returns float %f\n", ret); + PERF_EXIT(logf); + return ret; +} + +/*++ +Function: + log10f + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_log10f(float x) +{ + float ret; + PERF_ENTRY(log10f); + ENTRY("log10f (x=%f)\n", x); + +#if !HAVE_COMPATIBLE_LOG10 + errno = 0; +#endif // !HAVE_COMPATIBLE_LOG10 + + ret = log10f(x); + +#if !HAVE_COMPATIBLE_LOG10 + if ((errno == EDOM) && (x < 0)) + { + ret = PAL_NAN_FLT; // NaN + } +#endif // !HAVE_COMPATIBLE_LOG10 + + LOGEXIT("log10f returns float %f\n", ret); + PERF_EXIT(log10f); + return ret; +} + +/*++ +Function: + powf + +See MSDN. +--*/ +PALIMPORT float __cdecl PAL_powf(float x, float y) +{ + float ret; + PERF_ENTRY(powf); + ENTRY("powf (x=%f, y=%f)\n", x, y); + +#if !HAVE_COMPATIBLE_POW + if ((y == PAL_POSINF_FLT) && !isnan(x)) // +Inf + { + if (x == 1.0f) + { + ret = x; + } + else if (x == -1.0f) + { + ret = PAL_NAN_FLT; // NaN + } + else if ((x > -1.0f) && (x < 1.0f)) + { + ret = 0.0f; + } + else + { + ret = PAL_POSINF_FLT; // +Inf + } + } + else if ((y == PAL_NEGINF_FLT) && !isnan(x)) // -Inf + { + if (x == 1.0f) + { + ret = x; + } + else if (x == -1.0f) + { + ret = PAL_NAN_FLT; // NaN + } + else if ((x > -1.0f) && (x < 1.0f)) + { + ret = PAL_POSINF_FLT; // +Inf + } + else + { + ret = 0.0f; + } + } + else if (IS_FLT_NEGZERO(x) && (y == -1.0f)) + { + ret = PAL_NEGINF_FLT; // -Inf + } + else if ((x == 0.0f) && (y < 0.0f)) + { + ret = PAL_POSINF_FLT; // +Inf + } + else +#endif // !HAVE_COMPATIBLE_POW + + if ((y == 0.0f) && isnan(x)) + { + // Windows returns NaN for powf(NaN, 0), but POSIX specifies + // a return value of 1 for that case. We need to return + // the same result as Windows. + ret = PAL_NAN_FLT; + } + else + { + ret = powf(x, y); + } + +#if !HAVE_VALID_NEGATIVE_INF_POW + if ((ret == PAL_POSINF_FLT) && (x < 0) && isfinite(x) && (ceilf(y / 2) != floorf(y / 2))) + { + ret = PAL_NEGINF_FLT; // -Inf + } +#endif // !HAVE_VALID_NEGATIVE_INF_POW + +#if !HAVE_VALID_POSITIVE_INF_POW + /* + * The (ceil(y/2) == floor(y/2)) test is slower, but more robust for platforms where large y + * will return the wrong result for ((long) y % 2 == 0). See PAL_pow(double) above for more details. + */ + if ((ret == PAL_NEGINF_FLT) && (x < 0) && isfinite(x) && (ceilf(y / 2) == floorf(y / 2))) + { + ret = PAL_POSINF_FLT; // +Inf + } +#endif // !HAVE_VALID_POSITIVE_INF_POW + + LOGEXIT("powf returns float %f\n", ret); + PERF_EXIT(powf); + return ret; +} diff --git a/src/pal/src/cruntime/mbstring.cpp b/src/pal/src/cruntime/mbstring.cpp index dd4bcbbdce..ace2aa56c6 100644 --- a/src/pal/src/cruntime/mbstring.cpp +++ b/src/pal/src/cruntime/mbstring.cpp @@ -37,60 +37,6 @@ SET_DEFAULT_DEBUG_CHANNEL(CRT); /*++ Function: - _mbslen - -Determines the number of characters (code points) in a multibyte -character string. - -Parameters - -string Points to a multibyte character string. - -Return Values - -The mbslen subroutine returns the number of multibyte characters in a -multibyte character string. It returns 0 if the string parameter -points to a null character or if a character cannot be formed from the -string pointed to by this parameter. - ---*/ -size_t -__cdecl -_mbslen( - const unsigned char *string) -{ - size_t ret = 0; - CPINFO cpinfo; - PERF_ENTRY(_mbslen); - ENTRY("_mbslen (string=%p (%s))\n", string, string); - - if (string) - { - if (GetCPInfo(CP_ACP, &cpinfo) && cpinfo.MaxCharSize == 1) - { - ret = strlen((const char*)string); - } - else - { - while (*string) - { - if (IsDBCSLeadByteEx(CP_ACP, *string)) - { - ++string; - } - ++string; - ++ret; - } - } - } - - LOGEXIT("_mbslen returning size_t %u\n", ret); - PERF_EXIT(_mbslen); - return ret; -} - -/*++ -Function: _mbsinc Return Value diff --git a/src/pal/src/cruntime/path.cpp b/src/pal/src/cruntime/path.cpp index e5b955ebd9..4925af5b89 100644 --- a/src/pal/src/cruntime/path.cpp +++ b/src/pal/src/cruntime/path.cpp @@ -33,488 +33,6 @@ Revision History: SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/* ON_ERROR. A Helper macro for _?splitpath functions. */ -#define ON_ERROR if ( drive ) \ - {\ - drive[0] = 0;\ - }\ - if(dir)\ - {\ - dir[0] = 0;\ - }\ - if(fname)\ - {\ - fname[0] = 0;\ - }\ - if(ext)\ - {\ - ext[0] = 0;\ - }\ - goto done;\ - -/*++ -Function: - _wsplitpath - -See MSDN doc. - -Notes : - This implementation ignores drive letters as they should not be - present. If the drive argument is non-NULL, it always returns an empty - string. - File names in which the only period is at the beginning (like .bashrc, but - not .bashrc.bak), the file is treated as having no extension - (fname is ".bashrc", ext is "") - ---*/ -void -__cdecl -_wsplitpath( - const wchar_16 *dospath, - wchar_16 *drive, - wchar_16 *dir, - wchar_16 *fname, - wchar_16 *ext) -{ - WCHAR path[_MAX_PATH+1]; - LPCWSTR slash_ptr = NULL; - LPCWSTR period_ptr = NULL; - INT size = 0; - - PERF_ENTRY(_wsplitpath); - ENTRY("_wsplitpath (path=%p (%S), drive=%p, dir=%p, fname=%p, ext=%p)\n", - dospath?dospath:W16_NULLSTRING, - dospath?dospath:W16_NULLSTRING, drive, dir, fname, ext); - - /* Do performance intensive error checking only in debug builds. - - NOTE: This function must fail predictably across all platforms. - Under Windows this function throw an access violation if NULL - was passed in as the value for path. - - */ -#if _DEBUG - if ( !dospath ) - { - ERROR( "path cannot be NULL!\n" ); - } -#endif - - if( lstrlenW( dospath ) >= _MAX_PATH ) - { - ERROR("Path length is > _MAX_PATH (%d)!\n", _MAX_PATH); - ON_ERROR; - } - - - PAL_wcscpy(path, dospath); - FILEDosToUnixPathW(path); - - /* no drive letters in the PAL */ - if( drive != NULL ) - { - drive[0] = 0; - } - - /* find last path separator char */ - slash_ptr = PAL_wcsrchr(path, '/'); - - if( slash_ptr == NULL ) - { - TRACE("No path separator in path\n"); - slash_ptr = path - 1; - } - /* find extension separator, if any */ - period_ptr = PAL_wcsrchr(path, '.'); - - /* make sure we only consider periods after the last path separator */ - if( period_ptr < slash_ptr ) - { - period_ptr = NULL; - } - - /* if the only period in the file is a leading period (denoting a hidden - file), don't treat what follows as an extension */ - if( period_ptr == slash_ptr+1 ) - { - period_ptr = NULL; - } - - if( period_ptr == NULL ) - { - TRACE("No extension in path\n"); - period_ptr = path + lstrlenW(path); - } - - size = slash_ptr - path + 1; - if( dir != NULL ) - { - INT i; - - if( (size + 1 ) > _MAX_DIR ) - { - ERROR("Directory component needs %d characters, _MAX_DIR is %d\n", - size+1, _MAX_DIR); - ON_ERROR; - } - - memcpy(dir, path, size*sizeof(WCHAR)); - dir[size] = 0; - - /* only allow / separators in returned path */ - i = 0; - while( dir[ i ] ) - { - if( dir[ i ] == '\\' ) - { - dir[i]='/'; - } - i++; - } - } - - size = period_ptr-slash_ptr-1; - if( fname != NULL ) - { - if( (size+1) > _MAX_FNAME ) - { - ERROR("Filename component needs %d characters, _MAX_FNAME is %d\n", - size+1, _MAX_FNAME); - ON_ERROR; - } - memcpy(fname, slash_ptr+1, size*sizeof(WCHAR)); - fname[size] = 0; - } - - size = 1 + lstrlenW( period_ptr ); - if( ext != NULL ) - { - if( size > _MAX_EXT ) - { - ERROR("Extension component needs %d characters, _MAX_EXT is %d\n", - size, _MAX_EXT); - ON_ERROR; - } - memcpy(ext, period_ptr, size*sizeof(WCHAR)); - ext[size-1] = 0; - } - - TRACE("Path components are '%S' '%S' '%S'\n", dir, fname, ext); - -done: - - LOGEXIT("_wsplitpath returns.\n"); - PERF_EXIT(_wsplitpath); -} - - -/*++ -Function: - _splitpath - -See description above for _wsplitpath. - ---*/ -void -__cdecl -_splitpath( - const char *path, - char *drive, - char *dir, - char *fname, - char *ext) -{ - WCHAR w_path[_MAX_PATH]; - WCHAR w_dir[_MAX_DIR]; - WCHAR w_fname[_MAX_FNAME]; - WCHAR w_ext[_MAX_EXT]; - - PERF_ENTRY(_splitpath); - ENTRY("_splitpath (path=%p (%s), drive=%p, dir=%p, fname=%p, ext=%p)\n", - path?path:"NULL", - path?path:"NULL", drive, dir, fname, ext); - - /* Do performance intensive error checking only in debug builds. - - NOTE: This function must fail predictably across all platforms. - Under Windows this function throw an access violation if NULL - was passed in as the value for path. - - */ -#if _DEBUG - if ( !path ) - { - ERROR( "path cannot be NULL!\n" ); - } - - if( strlen( path ) >= _MAX_PATH ) - { - ERROR( "Path length is > _MAX_PATH (%d)!\n", _MAX_PATH); - } -#endif - - /* no drive letters in the PAL */ - if(drive) - { - drive[0] = '\0'; - } - - if(0 == MultiByteToWideChar(CP_ACP, 0, path, -1, w_path, _MAX_PATH)) - { - ASSERT("MultiByteToWideChar failed!\n"); - ON_ERROR; - } - - /* Call up to Unicode version; pass NULL for parameters the caller doesn't - care about */ - _wsplitpath(w_path, NULL, dir?w_dir:NULL, - fname?w_fname:NULL, ext?w_ext:NULL); - - /* Convert result back to MultiByte; report conversion errors but don't - stop because of them */ - - if(dir) - { - if(0 == WideCharToMultiByte(CP_ACP, 0, w_dir, -1, dir, _MAX_DIR, - NULL, NULL)) - { - ASSERT("WideCharToMultiByte failed!\n"); - ON_ERROR; - } - } - if(fname) - { - if(0 == WideCharToMultiByte(CP_ACP, 0, w_fname, -1, fname, _MAX_FNAME, - NULL, NULL)) - { - ASSERT("WideCharToMultiByte failed!\n"); - ON_ERROR; - } - } - if(ext) - { - if(0 == WideCharToMultiByte(CP_ACP, 0, w_ext, -1, ext, _MAX_EXT, - NULL, NULL)) - { - ASSERT("WideCharToMultiByte failed!\n"); - ON_ERROR; - } - } - -done: - LOGEXIT("_splitpath returns.\n"); - PERF_EXIT(_splitpath); -} - - - -/*++ -Function: - _makepath - -See MSDN doc. - ---*/ -void -__cdecl -_makepath( - char *path, - const char *drive, - const char *dir, - const char *fname, - const char *ext) -{ - UINT Length = 0; - - PERF_ENTRY(_makepath); - ENTRY( "_makepath (path=%p, drive=%p (%s), dir=%p (%s), fname=%p (%s), ext=%p (%s))\n", - path, drive ? drive:"NULL", drive ? drive:"NULL", dir ? dir:"NULL", dir ? dir:"NULL", fname ? fname:"NULL", fname ? fname:"NULL", - ext ? ext:"NULL", - ext ? ext:"NULL"); - - path[ 0 ] = '\0'; - - /* According to the pal documentation, host operating systems that - don't support drive letters, the "drive" parameter must always be null. */ - if ( drive != NULL && drive[0] != '\0' ) - { - ASSERT( "The drive parameter must always be NULL on systems that don't" - "support drive letters. drive is being ignored!.\n" ); - } - - if ( dir != NULL && dir[ 0 ] != '\0' ) - { - UINT DirLength = strlen( dir ); - Length += DirLength ; - - if ( Length < _MAX_PATH ) - { - strncat( path, dir, DirLength ); - if ( dir[ DirLength - 1 ] != '/' && dir[ DirLength - 1 ] != '\\' ) - { - if ( Length + 1 < _MAX_PATH ) - { - path[ Length ] = '/'; - Length++; - path[ Length ] = '\0'; - } - else - { - goto Max_Path_Error; - } - } - } - else - { - goto Max_Path_Error; - } - } - - if ( fname != NULL && fname[ 0 ] != '\0' ) - { - UINT fNameLength = strlen( fname ); - Length += fNameLength; - - if ( Length < _MAX_PATH ) - { - strncat( path, fname, fNameLength ); - } - else - { - goto Max_Path_Error; - } - } - - if ( ext != NULL && ext[ 0 ] != '\0' ) - { - UINT ExtLength = strlen( ext ); - Length += ExtLength; - - if ( ext[ 0 ] != '.' ) - { - /* Add a '.' */ - if ( Length + 1 < _MAX_PATH ) - { - path[ Length - ExtLength ] = '.'; - Length++; - path[ Length - ExtLength ] = '\0'; - strncat( path, ext, ExtLength ); - } - else - { - goto Max_Path_Error; - } - } - else - { - /* Already has a '.' */ - if ( Length < _MAX_PATH ) - { - strncat( path, ext, ExtLength ); - } - else - { - goto Max_Path_Error; - } - } - } - - FILEDosToUnixPathA( path ); - LOGEXIT( "_makepath returning void.\n" ); - PERF_EXIT(_makepath); - return; - -Max_Path_Error: - - ERROR( "path cannot be greater then _MAX_PATH\n" ); - path[ 0 ] = '\0'; - LOGEXIT( "_makepath returning void \n" ); - PERF_EXIT(_makepath); - return; -} - -/*++ -Function: - _wmakepath - -See MSDN doc. - ---*/ -void -__cdecl -_wmakepath( - wchar_16 *path, - const wchar_16 *drive, - const wchar_16 *dir, - const wchar_16 *fname, - const wchar_16 *ext) -{ - CHAR Dir[ _MAX_DIR ]={0}; - CHAR FileName[ _MAX_FNAME ]={0}; - CHAR Ext[ _MAX_EXT ]={0}; - CHAR Path[ _MAX_PATH ]={0}; - - PERF_ENTRY(_wmakepath); - ENTRY("_wmakepath (path=%p, drive=%p (%S), dir=%p (%S), fname=%p (%S), ext=%p (%S))\n", - path, drive ? drive:W16_NULLSTRING, drive ? drive:W16_NULLSTRING, dir ? dir:W16_NULLSTRING, dir ? dir:W16_NULLSTRING, - fname ? fname:W16_NULLSTRING, - fname ? fname:W16_NULLSTRING, ext ? ext:W16_NULLSTRING, ext ? ext:W16_NULLSTRING); - - /* According to the pal documentation, host operating systems that - don't support drive letters, the "drive" parameter must always be null. */ - if ( drive != NULL && drive[0] != '\0' ) - { - ASSERT( "The drive parameter must always be NULL on systems that don't" - "support drive letters. drive is being ignored!.\n" ); - } - - if ((dir != NULL) && WideCharToMultiByte( CP_ACP, 0, dir, -1, Dir, - _MAX_DIR, NULL, NULL ) == 0 ) - { - ASSERT( "An error occurred while converting dir to multibyte." - "Possible error: Length of dir is greater than _MAX_DIR.\n" ); - goto error; - } - - if ((fname != NULL) && WideCharToMultiByte( CP_ACP, 0, fname, -1, FileName, - _MAX_FNAME, NULL, NULL ) == 0 ) - { - ASSERT( "An error occurred while converting fname to multibyte." - "Possible error: Length of fname is greater than _MAX_FNAME.\n" ); - goto error; - } - - if ((ext != NULL) && WideCharToMultiByte( CP_ACP, 0, ext, -1, Ext, - _MAX_EXT, NULL, NULL ) == 0 ) - { - ASSERT( "An error occurred while converting ext to multibyte." - "Possible error: Length of ext is greater than _MAX_EXT.\n" ); - goto error; - } - - /* Call up to the ANSI _makepath. */ - _makepath_s( Path, sizeof(Path), NULL, Dir, FileName, Ext ); - - if ( MultiByteToWideChar( CP_ACP, 0, Path, -1, path, _MAX_PATH ) == 0 ) - { - ASSERT( "An error occurred while converting the back wide char." - "Possible error: The length of combined path is greater " - "than _MAX_PATH.\n" ); - goto error; - } - - LOGEXIT("_wmakepath returns void\n"); - PERF_EXIT(_wmakepath); - return; - -error: - *path = '\0'; - LOGEXIT("_wmakepath returns void\n"); - PERF_EXIT(_wmakepath); -} - - /*++ Function: _fullpath diff --git a/src/pal/src/cruntime/printf.cpp b/src/pal/src/cruntime/printf.cpp index 2d9d6e4b94..c437b8e39f 100644 --- a/src/pal/src/cruntime/printf.cpp +++ b/src/pal/src/cruntime/printf.cpp @@ -277,124 +277,6 @@ PAL_vprintf( /*++ Function: - wsprintfA - -See MSDN doc. ---*/ -int -PALAPIV -wsprintfA( - OUT LPSTR buffer, - IN LPCSTR format, - ...) -{ - LONG Length; - va_list ap; - - PERF_ENTRY(wsprintfA); - ENTRY("wsprintfA (buffer=%p, format=%p (%s))\n", buffer, format, format); - - va_start(ap, format); - Length = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), buffer, 1024, format, ap); - va_end(ap); - - LOGEXIT("wsprintfA returns int %d\n", Length); - PERF_EXIT(wsprintfA); - return Length; -} - -/*++ -Function: - wsprintfW - -See MSDN doc. ---*/ -int -PALAPIV -wsprintfW( - OUT LPWSTR buffer, - IN LPCWSTR format, - ...) -{ - LONG Length; - va_list ap; - - PERF_ENTRY(wsprintfW); - ENTRY("wsprintfW (buffer=%p, format=%p (%S))\n", buffer, format, format); - - va_start(ap, format); - Length = PAL__wvsnprintf(buffer, 1024, format, ap); - va_end(ap); - - LOGEXIT("wsprintfW returns int %d\n", Length); - PERF_EXIT(wsprintfW); - return Length; -} - - -/*++ -Function: - _snprintf - -See MSDN doc. ---*/ -int -__cdecl -_snprintf( - char *buffer, - size_t count, - const char *format, - ...) -{ - LONG Length; - va_list ap; - - PERF_ENTRY(_snprintf); - ENTRY("_snprintf (buffer=%p, count=%lu, format=%p (%s))\n", - buffer, (unsigned long) count, format, format); - - va_start(ap, format); - Length = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), buffer, count, format, ap); - va_end(ap); - - LOGEXIT("_snprintf returns int %d\n", Length); - PERF_EXIT(_snprintf); - return Length; -} - - -/*++ -Function: - _snwprintf - -See MSDN doc. ---*/ -int -__cdecl -_snwprintf( - wchar_16 *buffer, - size_t count, - const wchar_16 *format, - ...) -{ - LONG Length; - va_list ap; - - PERF_ENTRY(_snwprintf); - ENTRY("_snwprintf (buffer=%p, count=%lu, format=%p (%S))\n", - buffer, (unsigned long) count, format, format); - - va_start(ap, format); - Length = PAL__wvsnprintf(buffer, count, format, ap); - va_end(ap); - - LOGEXIT("_snwprintf returns int %d\n", Length); - PERF_EXIT(_snwprintf); - return Length; -} - -/*++ -Function: fwprintf See MSDN doc. @@ -1483,63 +1365,6 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) /*++ Function: - PAL_sscanf - -See MSDN doc. ---*/ -int -__cdecl -PAL_sscanf( - const char *buffer, - const char *format, - ...) -{ - int Length; - va_list ap; - - PERF_ENTRY(sscanf); - ENTRY("PAL_sscanf (buffer=%p (%s), format=%p (%s))\n", buffer, buffer, format, format); - - va_start(ap, format); - Length = PAL_vsscanf(buffer, format, ap); - va_end(ap); - - LOGEXIT("PAL_sscanf returns int %d\n", Length); - PERF_EXIT(sscanf); - return Length; -} - -/*++ -Function: - PAL_sprintf - -See MSDN doc. ---*/ -int -__cdecl -PAL_sprintf( - char *buffer, - const char *format, - ...) -{ - LONG Length; - va_list ap; - - PERF_ENTRY(sprintf); - ENTRY("PAL_sprintf (buffer=%p, format=%p (%s))\n", buffer, format, format); - - va_start(ap, format); - Length = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), buffer, 0x7fffffff, format, ap); - va_end(ap); - - LOGEXIT("PAL_sprintf returns int %d\n", Length); - PERF_EXIT(sprintf); - return Length; -} - - -/*++ -Function: PAL_swprintf See MSDN doc. @@ -1649,33 +1474,6 @@ PAL_vswprintf(wchar_16 *buffer, } -/*++ -Function: - _vsnwprintf - -See MSDN doc. ---*/ -int -__cdecl -_vsnwprintf(wchar_16 *buffer, - size_t count, - const wchar_16 *format, - va_list argptr) -{ - LONG Length; - - PERF_ENTRY(_vsnwprintf); - ENTRY("_vsnwprintf (buffer=%p, count=%lu, format=%p (%S), argptr=%p)\n", - buffer, (unsigned long) count, format, format, argptr); - - Length = PAL__wvsnprintf(buffer, count, format, argptr); - - LOGEXIT("_vsnwprintf returns int %d\n", Length); - PERF_EXIT(_vsnwprintf); - - return Length; -} - #if SSCANF_CANNOT_HANDLE_MISSING_EXPONENT /*++ Function: diff --git a/src/pal/src/cruntime/string.cpp b/src/pal/src/cruntime/string.cpp index 23781d8b39..abe6d136f0 100644 --- a/src/pal/src/cruntime/string.cpp +++ b/src/pal/src/cruntime/string.cpp @@ -151,61 +151,6 @@ _strlwr( return orig; } - -/*++ -Function: - _swab - -Swaps bytes. - -Return Value - -None - -Parameters - -src Data to be copied and swapped -dest Storage location for swapped data -n Number of bytes to be copied and swapped - -Remarks - -The _swab function copies n bytes from src, swaps each pair of -adjacent bytes, and stores the result at dest. The integer n should be -an even number to allow for swapping. _swab is typically used to -prepare binary data for transfer to a machine that uses a different -byte order. - -Example - -char from[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -char to[] = ".........................."; - -printf("Before:\n%s\n%s\n\n", from, to); -_swab(from, to, strlen(from)); -printf("After:\n%s\n%s\n\n", from, to); - -Before: -ABCDEFGHIJKLMNOPQRSTUVWXYZ -.......................... - -After: -ABCDEFGHIJKLMNOPQRSTUVWXYZ -BADCFEHGJILKNMPORQTSVUXWZY - ---*/ -void -__cdecl -_swab(char *src, char *dest, int n) -{ - PERF_ENTRY(_swab); - ENTRY("_swab (src=%p (%s), dest=%p (%s), n=%d)\n", src?src:"NULL", src?src:"NULL", dest?dest:"NULL", dest?dest:"NULL", n); - swab(src, dest, n); - LOGEXIT("_swab returning\n"); - PERF_EXIT(_swab); -} - - /*++ Function: PAL_strtoul diff --git a/src/pal/src/cruntime/wchar.cpp b/src/pal/src/cruntime/wchar.cpp index 2d244a639f..3de065e361 100644 --- a/src/pal/src/cruntime/wchar.cpp +++ b/src/pal/src/cruntime/wchar.cpp @@ -73,146 +73,6 @@ wtolower(wchar_16 c) } -/******************************************************************************* -Function: - Internal_i64tow - -Parameters: - value - - INT64 value to be converted to a string - string - - out buffer to place interger string - radix - - numeric base to convert to - isI64 - - TRUE if value is INT64, FALSE if value is a long - -Note: - - only a radix of ten (and value < 0) will result in a negative - sign in the output buffer -*******************************************************************************/ -LPWSTR Internal_i64tow(INT64 value, LPWSTR string, int radix, BOOL isI64) -{ - int length = 0; - int n; - int r; - UINT64 uval = value; - LPWSTR stringPtr = string; - int start = 0; - int end; - WCHAR tempCh; - - if (radix < 2 || radix > 36) - { - ASSERT( "Invalid radix, radix must be between 2 and 36\n" ); - SetLastError(ERROR_INVALID_PARAMETER); - return string; - } - if (FALSE == isI64) - { - uval = (ULONG) uval; - } - if (10 == radix && value < 0) - { - uval = value * -1; - } - if(0 == uval) - { - ++length; - *stringPtr++ = '0'; - } - else while (uval > 0) - { - ++length; - n = uval / radix; - r = uval - (n * radix); - uval /= radix; - if (r > 9) - { - *stringPtr++ = r + 87; - } - else - { - *stringPtr++ = r + 48; - } - } - if (10 == radix && value < 0) - { - *stringPtr++ = '-'; - ++length; - } - *stringPtr = 0; /* end the string */ - - /* reverse the string */ - end = length - 1; - while (start < end) - { - tempCh = string[start]; - string[start] = string[end]; - string[end] = tempCh; - ++start; - --end; - } - - return string; -} - -/*-- -Function: - _itow - -16-bit wide character version of the ANSI tolower() function. - - --*/ -wchar_16 * -__cdecl -_itow( - int value, - wchar_16 *string, - int radix) -{ - wchar_16 *ret; - - PERF_ENTRY(_itow); - ENTRY("_itow (value=%d, string=%p, radix=%d)\n", - value, string, radix); - - ret = Internal_i64tow(value, string, radix, FALSE); - - LOGEXIT("_itow returns wchar_t* %p\n", ret); - PERF_EXIT(_itow); - - return ret; -} - -/*-- -Function: - _i64tow - -See MSDN doc ---*/ -wchar_16 * - __cdecl -_i64tow( - __int64 value, - wchar_16 *string, - int radix) -{ - wchar_16 *ret; - - PERF_ENTRY(_i64tow); - ENTRY("_i64tow (value=%ld, string=%p, radix=%d)\n", - value, string, radix); - - ret = Internal_i64tow(value, string, radix, TRUE); - - LOGEXIT("_i64tow returns wchar_t* %p\n", ret); - PERF_EXIT(_i64tow); - - return ret; -} - - /*-- Function: _wtoi @@ -1558,77 +1418,6 @@ PAL_wcstod( const wchar_16 * nptr, wchar_16 **endptr ) } /*++ -Function : - - _ui64tow - -See MSDN for more details. ---*/ -wchar_16 * -__cdecl -_ui64tow( unsigned __int64 value , wchar_16 * string , int radix ) -{ - UINT ReversedIndex = 0; - WCHAR ReversedString[ 65 ]; - LPWSTR lpString = string; - UINT Index = 0; - - PERF_ENTRY(_ui64tow); - ENTRY( "_ui64tow( value=%I64d, string=%p (%S), radix=%d )\n", - value, string, string, radix ); - - if ( !string ) - { - ERROR( "string has to be a valid pointer.\n" ); - LOGEXIT( "_ui64tow returning NULL.\n" ); - PERF_EXIT(_ui64tow); - return NULL; - } - if ( radix < 2 || radix > 36 ) - { - ERROR( "radix has to be between 2 and 36.\n" ); - LOGEXIT( "_ui64tow returning NULL.\n" ); - PERF_EXIT(_ui64tow); - return NULL; - } - - if(0 == value) - { - ReversedString[0] = '0'; - Index++; - } - else while ( value ) - { - int temp = value % radix; - value /= radix; - - if ( temp < 10 ) - { - ReversedString[ Index ] = temp + '0'; - Index++; - } - else - { - ReversedString[ Index ] = temp - 10 + 'a'; - Index++; - } - } - - /* Reverse the string. */ - ReversedIndex = Index; - for ( Index = 0; ReversedIndex > 0; ReversedIndex--, Index++ ) - { - string[ Index ] = ReversedString[ ReversedIndex - 1 ]; - } - - string[ Index ] = '\0'; - LOGEXIT( "_ui64tow returning %p (%S).\n", lpString , lpString ); - PERF_EXIT(_ui64tow); - return lpString; -} - - -/*++ Function: iswdigit |