diff --git a/lib/Backend/Backend.h b/lib/Backend/Backend.h index 722b235d20d..183fa6fd97a 100644 --- a/lib/Backend/Backend.h +++ b/lib/Backend/Backend.h @@ -1,10 +1,13 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. +// Copyright (c) ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #pragma once +#ifndef USING_PAL_STDLIB #include +#endif // ================= // Runtime Includes diff --git a/lib/Common/Memory/CustomHeap.cpp b/lib/Common/Memory/CustomHeap.cpp index 7fed0ef0c98..9376df978a9 100644 --- a/lib/Common/Memory/CustomHeap.cpp +++ b/lib/Common/Memory/CustomHeap.cpp @@ -8,7 +8,7 @@ #if ENABLE_NATIVE_CODEGEN || DYNAMIC_INTERPRETER_THUNK #include "Memory/XDataAllocator.h" -#if defined(_M_ARM) +#if defined(_M_ARM) && defined(_WIN32) #include #endif #include "CustomHeap.h" diff --git a/lib/Runtime/Base/ittnotify_config.h b/lib/Runtime/Base/ittnotify_config.h index e25236539ac..8e3d260b940 100644 --- a/lib/Runtime/Base/ittnotify_config.h +++ b/lib/Runtime/Base/ittnotify_config.h @@ -1,5 +1,6 @@ //------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft Corporation and contributors. All rights reserved. +// Copyright (c) ChakraCore Project Contributors. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #ifndef _ITTNOTIFY_CONFIG_H_ @@ -73,9 +74,6 @@ #include #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ #include -#if defined(UNICODE) || defined(_UNICODE) -#include -#endif /* UNICODE || _UNICODE */ #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ #ifndef ITTAPI_CDECL @@ -201,9 +199,6 @@ typedef CRITICAL_SECTION mutex_t; #define strong_alias(name, aliasname) /* empty for Windows */ #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ #include -#if defined(UNICODE) || defined(_UNICODE) -#include -#endif /* UNICODE */ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */ #endif /* _GNU_SOURCE */ diff --git a/pal/inc/mbusafecrt.h b/pal/inc/mbusafecrt.h index 1bf6ce79ace..afc28b98130 100644 --- a/pal/inc/mbusafecrt.h +++ b/pal/inc/mbusafecrt.h @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*** * mbusafecrt.h - public declarations for SafeCRT lib @@ -64,11 +67,7 @@ extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* extern char* strtok_s( char* inString, const char* inControl, char** ioContext ); extern WCHAR* wcstok_s( WCHAR* inString, const WCHAR* inControl, WCHAR** ioContext ); -// strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website) -#ifndef SUPPRESS_STRNLEN - extern size_t strnlen( const char* inString, size_t inMaxSize ); - extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize ); -#endif +extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize ); extern errno_t _itoa_s( int inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); extern errno_t _itow_s( int inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); diff --git a/pal/inc/pal.h b/pal/inc/pal.h index 20ca7a80d8e..cd158efdd3a 100644 --- a/pal/inc/pal.h +++ b/pal/inc/pal.h @@ -6103,7 +6103,6 @@ CoCreateGuid(OUT GUID * pguid); #define vswprintf PAL_vswprintf #define fopen PAL_fopen #define strtok PAL_strtok -#define strtoul PAL_strtoul #define fprintf PAL_fprintf #define fwprintf PAL_fwprintf #define vfprintf PAL_vfprintf @@ -6137,7 +6136,6 @@ CoCreateGuid(OUT GUID * pguid); #define mkstemp PAL_mkstemp #define rename PAL_rename #define unlink PAL_unlink -#define _strdup PAL__strdup #define _getcwd PAL__getcwd #define _open PAL__open #define _close PAL__close @@ -6180,7 +6178,6 @@ PALIMPORT void * __cdecl memchr(const void *, int, size_t); PALIMPORT size_t __cdecl strlen(const char *); PALIMPORT int __cdecl strcmp(const char*, const char *); PALIMPORT int __cdecl strncmp(const char*, const char *, size_t); -PALIMPORT int __cdecl _strnicmp(const char *, const char *, size_t); PALIMPORT char * __cdecl strcat(char *, const char *); PALIMPORT char * __cdecl strncat(char *, const char *, size_t); PALIMPORT char * __cdecl strcpy(char *, const char *); @@ -6198,7 +6195,7 @@ PALIMPORT int __cdecl sscanf(const char *, const char *, ...); PALIMPORT int __cdecl atoi(const char *); PALIMPORT LONG __cdecl atol(const char *); //PALIMPORT long long int __cdecl atoll(const char *) __THROW; -PALIMPORT ULONG __cdecl strtoul(const char *, char **, int); +PALIMPORT unsigned long __cdecl strtoul(const char *, char **, int); PALIMPORT double __cdecl atof(const char *); PALIMPORT double __cdecl strtod(const char *, char **); PALIMPORT int __cdecl isprint(int); @@ -6218,7 +6215,7 @@ PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t); PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t); PALIMPORT void * __cdecl memmove_xplat(void *, const void *, size_t); PALIMPORT char * __cdecl _strlwr(char *); -PALIMPORT int __cdecl _stricmp(const char *, const char *); +PALIMPORT int __cdecl strcasecmp(const char *, const char *); PALIMPORT int __cdecl _snprintf(char *, size_t, const char *, ...); PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int); PALIMPORT char * __cdecl _ecvt(double, int, int *, int *); diff --git a/pal/inc/rt/safecrt.h b/pal/inc/rt/safecrt.h index 1d75ff280ca..2a885b32c58 100644 --- a/pal/inc/rt/safecrt.h +++ b/pal/inc/rt/safecrt.h @@ -1,8 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- // /*** @@ -2409,34 +2411,11 @@ unsigned char * __cdecl _mbstok_s(unsigned char *_String, const unsigned char *_ #endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */ #ifndef PAL_STDCPP_COMPAT -/* strnlen */ /* - * strnlen, wcsnlen ; + * wcsnlen ; * returns inMaxSize if the null character is not found. */ -_SAFECRT__EXTERN_C -size_t __cdecl strnlen(const char* inString, size_t inMaxSize); - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -size_t __cdecl strnlen(const char* inString, size_t inMaxSize) -{ - size_t n; - - /* Note that we do not check if s == nullptr, because we do not - * return errno_t... - */ - - for (n = 0; n < inMaxSize && *inString; n++, inString++) - ; - - return n; -} - -#endif -/* wcsnlen */ _SAFECRT__EXTERN_C size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize); diff --git a/pal/src/CMakeLists.txt b/pal/src/CMakeLists.txt index 50bf556541f..03005d2bd97 100644 --- a/pal/src/CMakeLists.txt +++ b/pal/src/CMakeLists.txt @@ -99,7 +99,6 @@ set(SOURCES cruntime/printf.cpp cruntime/printfcpp.cpp cruntime/silent_printf.cpp - cruntime/string.cpp cruntime/stringtls.cpp cruntime/thread.cpp cruntime/wchar.cpp diff --git a/pal/src/config.h.in b/pal/src/config.h.in index 15e4a4c0deb..de1cb273e21 100644 --- a/pal/src/config.h.in +++ b/pal/src/config.h.in @@ -44,6 +44,7 @@ #cmakedefine01 HAVE_GMTIME_R #cmakedefine01 HAVE_TIMEGM #cmakedefine01 HAVE__SNWPRINTF +#cmakedefine01 HAVE_WCSNLEN #cmakedefine01 HAVE_POLL #cmakedefine01 HAVE_STATVFS #cmakedefine01 HAVE_THREAD_SELF diff --git a/pal/src/configure.cmake b/pal/src/configure.cmake index b0c128e0a1f..36eaef5969b 100644 --- a/pal/src/configure.cmake +++ b/pal/src/configure.cmake @@ -58,6 +58,7 @@ check_function_exists(localtime_r HAVE_LOCALTIME_R) check_function_exists(gmtime_r HAVE_GMTIME_R) check_function_exists(timegm HAVE_TIMEGM) check_function_exists(_snwprintf HAVE__SNWPRINTF) +check_function_exists(wcsnlen HAVE_WSCNLEN) check_function_exists(poll HAVE_POLL) check_function_exists(statvfs HAVE_STATVFS) check_function_exists(thread_self HAVE_THREAD_SELF) diff --git a/pal/src/cruntime/file.cpp b/pal/src/cruntime/file.cpp index c5da5e3dcbd..de0c6ad72f3 100644 --- a/pal/src/cruntime/file.cpp +++ b/pal/src/cruntime/file.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -283,10 +286,10 @@ PAL_fopen(const char * fileName, const char * mode) goto done; } - UnixFileName = PAL__strdup(fileName); + UnixFileName = strdup(fileName); if (UnixFileName == NULL ) { - ERROR("PAL__strdup() failed\n"); + ERROR("strdup() failed\n"); SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto done; } diff --git a/pal/src/cruntime/malloc.cpp b/pal/src/cruntime/malloc.cpp index 2cc68e4cabe..6c9d7def020 100644 --- a/pal/src/cruntime/malloc.cpp +++ b/pal/src/cruntime/malloc.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -114,22 +117,3 @@ CorUnix::InternalMalloc( pvMem = (void*)malloc(szSize); return pvMem; } - -char * -__cdecl -PAL__strdup( - const char *c_szStr - ) -{ - return InternalStrdup(c_szStr); -} - -char * -CorUnix::InternalStrdup( - const char *c_szStr - ) -{ - char *pszStrCopy; - pszStrCopy = strdup(c_szStr); - return pszStrCopy; -} diff --git a/pal/src/cruntime/misc.cpp b/pal/src/cruntime/misc.cpp index 6ad088c07a6..c9dca7a1642 100644 --- a/pal/src/cruntime/misc.cpp +++ b/pal/src/cruntime/misc.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -433,7 +436,7 @@ BOOL MiscPutenv(const char *string, BOOL deleteIfEmpty) // See if we are replacing an item or adding one. // Make our copy up front, since we'll use it either way. - copy = InternalStrdup(string); + copy = strdup(string); if (copy == NULL) { goto done; diff --git a/pal/src/cruntime/string.cpp b/pal/src/cruntime/string.cpp deleted file mode 100644 index 1c5fd420cff..00000000000 --- a/pal/src/cruntime/string.cpp +++ /dev/null @@ -1,294 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*++ - - - -Module Name: - - string.cpp - -Abstract: - - Implementation of the string functions in the C runtime library that are Windows specific. - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/cruntime.h" - -#include -#include -#include -#include -#include -#include - - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/*++ -Function: - _strnicmp - -compare at most count characters from two strings, ignoring case - -The strnicmp() function compares, with case insensitivity, at most count -characters from s1 to s2. All uppercase characters from s1 and s2 are -mapped to lowercase for the purposes of doing the comparison. - -Returns: - -Value Meaning - -< 0 s1 is less than s2 -0 s1 is equal to s2 -> 0 s1 is greater than s2 - ---*/ -int -__cdecl -_strnicmp( const char *s1, const char *s2, size_t count ) -{ - int ret; - - PERF_ENTRY(_strnicmp); - ENTRY("_strnicmp (s1=%p (%s), s2=%p (%s), count=%d)\n", s1?s1:"NULL", s1?s1:"NULL", s2?s2:"NULL", s2?s2:"NULL", count); - - ret = strncasecmp(s1, s2, count ); - - LOGEXIT("_strnicmp returning int %d\n", ret); - PERF_EXIT(_strnicmp); - return ret; -} - -/*++ -Function: - _stricmp - -compare two strings, ignoring case - -The stricmp() function compares, with case insensitivity, the string -pointed to by s1 to the string pointed to by s2. All uppercase -characters from s1 and s2 are mapped to lowercase for the purposes of -doing the comparison. - -Returns: - -Value Meaning - -< 0 s1 is less than s2 -0 s1 is equal to s2 -> 0 s1 is greater than s2 - ---*/ -int -__cdecl -_stricmp( - const char *s1, - const char *s2) -{ - int ret; - - PERF_ENTRY(_stricmp); - ENTRY("_stricmp (s1=%p (%s), s2=%p (%s))\n", s1?s1:"NULL", s1?s1:"NULL", s2?s2:"NULL", s2?s2:"NULL"); - - ret = strcasecmp(s1, s2); - - LOGEXIT("_stricmp returning int %d\n", ret); - PERF_EXIT(_stricmp); - return ret; -} - - -/*++ -Function: - _strlwr - -Convert a string to lowercase. - - -This function returns a pointer to the converted string. Because the -modification is done in place, the pointer returned is the same as the -pointer passed as the input argument. No return value is reserved to -indicate an error. - -Parameter - -string Null-terminated string to convert to lowercase - -Remarks - -The _strlwr function converts any uppercase letters in string to -lowercase as determined by the LC_CTYPE category setting of the -current locale. Other characters are not affected. For more -information on LC_CTYPE, see setlocale. - ---*/ -char * -__cdecl -_strlwr( - char *str) -{ - char *orig = str; - - PERF_ENTRY(_strlwr); - ENTRY("_strlwr (str=%p (%s))\n", str?str:"NULL", str?str:"NULL"); - - while (*str) - { - *str = tolower(*str); - str++; - } - - LOGEXIT("_strlwr returning char* %p (%s)\n", orig?orig:"NULL", orig?orig:"NULL"); - PERF_EXIT(_strlwr); - return orig; -} - - -/*++ -Function: - PAL_strtoul - -Convert string to an unsigned long-integer value. - -Return Value - -strtoul returns the converted value, if any, or ULONG_MAX on -overflow. It returns 0 if no conversion can be performed. errno is -set to ERANGE if overflow or underflow occurs. - -Parameters - -szNumber Null-terminated string to convert to a ULONG -pszEnd Pointer to character that stops scan -nBase Number base to use - -Remarks - -strtoul stops reading the string szNumber at the first character it cannot -recognize as part of a number. This may be the terminating null -character, or it may be the first numeric character greater than or -equal to base. The LC_NUMERIC category setting of the current locale -determines recognition of the radix character in szNumber; for more -information, see setlocale. If pszEnd is not NULL, a pointer to the -character that stopped the scan is stored at the location pointed to -by pszEnd. If no conversion can be performed (no valid digits were -found or an invalid base was specified), the value of szNumber is stored -at the location pointed to by pszEnd. - -Notes : - MSDN states that only space and tab are accepted as leading whitespace, but - tests indicate that other whitespace characters (newline, carriage return, - etc) are also accepted. This matches the behavior on Unix systems. - - For strtoul, we need to check if the value to be returned - is outside the 32 bit range. If so, the returned value needs to be set - as appropriate, according to the MSDN pages and in all instances errno - must be set to ERANGE (The one exception is converting a string - representing a negative value to unsigned long). - Note that on 64 bit Windows, long's are still 32 bit. Thus, to match - Windows behavior, we must return long's in the 32 bit range. - --*/ - -/* The use of ULONG is by design, to ensure that a 32 bit value is always -returned from this function. If "unsigned long" is used instead of ULONG, -then a 64 bit value could be returned on 64 bit platforms like HP-UX, thus -breaking Windows behavior. */ -ULONG -__cdecl -PAL_strtoul(const char *szNumber, char **pszEnd, int nBase) -{ - unsigned long ulResult; - - PERF_ENTRY(strtoul); - ENTRY("strtoul (szNumber=%p (%s), pszEnd=%p, nBase=%d)\n", - szNumber?szNumber:"NULL", - szNumber?szNumber:"NULL", - pszEnd, - nBase); - - ulResult = strtoul(szNumber, pszEnd, nBase); - -#ifdef BIT64 - if (ulResult > _UI32_MAX) - { - char ch = *szNumber; - while (isspace(ch)) - { - ch = *szNumber++; - } - /* If the string represents a positive number that is greater than - _UI32_MAX, set errno to ERANGE. Otherwise, don't set errno - to match Windows behavior. */ - if (ch != '-') - { - ulResult = _UI32_MAX; - errno = ERANGE; - } - } -#endif - - LOGEXIT("strtoul returning unsigned long %lu\n", ulResult); - PERF_EXIT(wcstoul); - - /* When returning unsigned long res from this function, it will be - implicitly cast to ULONG. This handles situations where a string that - represents a negative number is passed in to strtoul. The Windows - behavior is analogous to taking the binary equivalent of the negative - value and treating it as a positive number. Returning a ULONG from - this function, as opposed to native unsigned long, allows us to match - this behavior. The explicit cast to ULONG below is used to silence any - potential warnings due to the implicit casting. */ - return (ULONG)ulResult; - -} - - -/*++ -Function: - PAL_atol - -Convert string to a long value. - -Return Value - -atol returns the converted value, if any. In the case of overflow, -the return value is undefined. - -Parameters - -szNumber Null-terminated string to convert to a LONG ---*/ - -/* The use of LONG is by design, to ensure that a 32 bit value is always -returned from this function. If "long" is used instead of LONG, then a 64 bit -value could be returned on 64 bit platforms like HP-UX, thus breaking -Windows behavior. */ -LONG -__cdecl -PAL_atol(const char *szNumber) -{ - long lResult; - - PERF_ENTRY(atol); - ENTRY("atol (szNumber=%p (%s))\n", - szNumber?szNumber:"NULL" - ); - - lResult = atol(szNumber); - - LOGEXIT("atol returning long %ld\n", (LONG)lResult); - PERF_EXIT(atol); - /* This explicit cast to LONG is used to silence any potential warnings - due to implicitly casting the native long lResult to LONG when returning. */ - return (LONG)lResult; - -} diff --git a/pal/src/file/directory.cpp b/pal/src/file/directory.cpp index 580651bd39f..3982517d9b8 100644 --- a/pal/src/file/directory.cpp +++ b/pal/src/file/directory.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -553,10 +556,10 @@ CreateDirectoryA( goto done; } - UnixPathName = PAL__strdup(lpPathName); + UnixPathName = strdup(lpPathName); if (UnixPathName == NULL ) { - ERROR("PAL__strdup() failed\n"); + ERROR("strdup() failed\n"); dwLastError = ERROR_NOT_ENOUGH_MEMORY; goto done; } @@ -685,10 +688,10 @@ SetCurrentDirectoryA( goto done; } - UnixPathName = PAL__strdup(lpPathName); + UnixPathName = strdup(lpPathName); if (UnixPathName == NULL ) { - ERROR("PAL__strdup() failed\n"); + ERROR("strdup() failed\n"); dwLastError = ERROR_NOT_ENOUGH_MEMORY; goto done; } diff --git a/pal/src/file/pal_file.cpp b/pal/src/file/pal_file.cpp index 5371c1a3f85..5da2b02cd32 100644 --- a/pal/src/file/pal_file.cpp +++ b/pal/src/file/pal_file.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -169,9 +172,9 @@ void FILEGetProperNotFoundError( LPSTR lpPath, LPDWORD lpErrorCode ) return; } - if ( NULL == ( lpDupedPath = InternalStrdup( lpPath ) ) ) + if ( NULL == ( lpDupedPath = strdup( lpPath ) ) ) { - ERROR( "InternalStrdup() failed!\n" ); + ERROR( "strdup() failed!\n" ); *lpErrorCode = ERROR_NOT_ENOUGH_MEMORY; return; } @@ -270,10 +273,10 @@ CorUnix::InternalCanonicalizeRealPath(LPCSTR lpUnixPath, LPSTR lpBuffer, DWORD c lpRealPath = realpath(lpUnixPath, lpBuffer); #else // !REALPATH_SUPPORTS_NONEXISTENT_FILES - lpExistingPath = InternalStrdup(lpUnixPath); + lpExistingPath = strdup(lpUnixPath); if (lpExistingPath == NULL) { - ERROR ("InternalStrdup failed with error %d\n", errno); + ERROR ("strdup failed with error %d\n", errno); palError = ERROR_NOT_ENOUGH_MEMORY; goto LExit; } @@ -516,10 +519,10 @@ CorUnix::InternalCreateFile( goto done; } - lpUnixPath = InternalStrdup(lpFileName); + lpUnixPath = strdup(lpFileName); if ( lpUnixPath == NULL ) { - ERROR("InternalStrdup() failed\n"); + ERROR("strdup() failed\n"); palError = ERROR_NOT_ENOUGH_MEMORY; goto done; } @@ -1213,7 +1216,7 @@ DeleteFileA( if (palError != NO_ERROR) { InternalFree(lpFullUnixFileName); - lpFullUnixFileName = InternalStrdup(lpUnixFileName); + lpFullUnixFileName = strdup(lpUnixFileName); if (!lpFullUnixFileName) { palError = ERROR_NOT_ENOUGH_MEMORY; @@ -3954,10 +3957,10 @@ CopyFileA( } /* Need to preserve the owner/group and chmod() flags */ - lpUnixPath = InternalStrdup(lpExistingFileName); + lpUnixPath = strdup(lpExistingFileName); if ( lpUnixPath == NULL ) { - ERROR("InternalStrdup() failed\n"); + ERROR("strdup() failed\n"); pThread->SetLastError(FILEGetLastErrorFromErrno()); goto done; } @@ -3984,10 +3987,10 @@ CopyFileA( } InternalFree(lpUnixPath); - lpUnixPath = InternalStrdup(lpNewFileName); + lpUnixPath = strdup(lpNewFileName); if ( lpUnixPath == NULL ) { - ERROR("InternalStrdup() failed\n"); + ERROR("strdup() failed\n"); pThread->SetLastError(FILEGetLastErrorFromErrno()); goto done; } @@ -4111,9 +4114,9 @@ SetFileAttributesA( goto done; } - if ((UnixFileName = InternalStrdup(lpFileName)) == NULL) + if ((UnixFileName = strdup(lpFileName)) == NULL) { - ERROR("InternalStrdup() failed\n"); + ERROR("strdup() failed\n"); dwLastError = ERROR_NOT_ENOUGH_MEMORY; goto done; } diff --git a/pal/src/file/pal_path.cpp b/pal/src/file/pal_path.cpp index c65bc4ef643..6537192fa94 100644 --- a/pal/src/file/pal_path.cpp +++ b/pal/src/file/pal_path.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -83,7 +86,7 @@ GetFullPathNameA( if(fullPath) { - lpUnixPath = PAL__strdup( lpFileName ); + lpUnixPath = strdup( lpFileName ); if(NULL == lpUnixPath) { ERROR("strdup() failed; error is %d (%s)\n", diff --git a/pal/src/include/pal/malloc.hpp b/pal/src/include/pal/malloc.hpp index bee084e78b4..2358646ae02 100644 --- a/pal/src/include/pal/malloc.hpp +++ b/pal/src/include/pal/malloc.hpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -50,12 +53,6 @@ extern "C" PAL_free( void *pvMem ); - - char * - __cdecl - PAL__strdup( - const char *c_szStr - ); } inline void* operator new(size_t, void* p) throw () { return p; } @@ -79,11 +76,6 @@ namespace CorUnix{ void *pvMem ); - char * - InternalStrdup( - const char *c_szStr - ); - // Define common code for "new" style allocators below. #define INTERNAL_NEW_COMMON() \ T *pMem = (T*)InternalMalloc(sizeof(T)); \ diff --git a/pal/src/include/pal/palinternal.h b/pal/src/include/pal/palinternal.h index bd6f77cacf0..3d494fe9a9a 100644 --- a/pal/src/include/pal/palinternal.h +++ b/pal/src/include/pal/palinternal.h @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -179,9 +182,11 @@ function_name() to call the system's implementation #define memcmp DUMMY_memcmp #define memset DUMMY_memset #define memchr DUMMY_memchr +#define strdup DUMMY_strdup #define strlen DUMMY_strlen -#define strnlen DUMMY_strnlen +#define strtoul DUMMY_strtoul #define stricmp DUMMY_stricmp +#define strcasecmp DUMMY_strcasecmp #define strstr DUMMY_strstr #define strcmp DUMMY_strcmp #define strcat DUMMY_strcat @@ -201,6 +206,9 @@ function_name() to call the system's implementation #if HAVE__SNWPRINTF #define _snwprintf DUMMY__snwprintf #endif /* HAVE__SNWPRINTF */ +#if HAVE_WSCNLEN +#define wcsnlen DUMMY_wcsnlen +#endif #define tolower DUMMY_tolower #define toupper DUMMY_toupper #define islower DUMMY_islower @@ -351,8 +359,8 @@ function_name() to call the system's implementation #undef memset #undef memmove #undef memchr +#undef strdup #undef strlen -#undef strnlen #undef stricmp #undef strstr #undef strcmp @@ -361,6 +369,7 @@ function_name() to call the system's implementation #undef strncat #undef strcpy #undef strncmp +#undef strcasecmp #undef strncpy #undef strchr #undef strrchr @@ -480,6 +489,9 @@ function_name() to call the system's implementation #undef _snwprintf #endif /* HAVE__SNWPRINTF */ #undef sscanf +#if HAVE_WSCNLEN +#undef wcsnlen +#endif #undef wcstod #undef wcstol #undef wcstoul diff --git a/pal/src/init/pal.cpp b/pal/src/init/pal.cpp index db858de4b9d..87774153702 100644 --- a/pal/src/init/pal.cpp +++ b/pal/src/init/pal.cpp @@ -942,7 +942,7 @@ static LPWSTR INIT_FindEXEPath(LPCSTR exe_name) } /* get our own copy of env_path so we can modify it */ - env_path=InternalStrdup(env_path); + env_path=strdup(env_path); if(!env_path) { ERROR("Not enough memory to copy $PATH!\n"); diff --git a/pal/src/loader/module.cpp b/pal/src/loader/module.cpp index 5f751afa509..e2f3ddea6f8 100644 --- a/pal/src/loader/module.cpp +++ b/pal/src/loader/module.cpp @@ -1,7 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -178,10 +181,10 @@ LoadLibraryExA( } /* do the Dos/Unix conversion on our own copy of the name */ - lpstr = InternalStrdup(lpLibFileName); + lpstr = strdup(lpLibFileName); if (!lpstr) { - ERROR("InternalStrdup failure!\n"); + ERROR("strdup failure!\n"); SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto Done; } diff --git a/pal/src/misc/dbgmsg.cpp b/pal/src/misc/dbgmsg.cpp index f9a2daeade3..be07412a401 100644 --- a/pal/src/misc/dbgmsg.cpp +++ b/pal/src/misc/dbgmsg.cpp @@ -1,8 +1,10 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - +//------------------------------------------------------------------------------------------------------- +// ChakraCore/Pal +// Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors +// and edits (c) copyright the ChakraCore Contributors. +// See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- /*++ @@ -174,7 +176,7 @@ BOOL DBG_init_channels(void) } else { - env_pcache = env_workstring = PAL__strdup(env_string); + env_pcache = env_workstring = strdup(env_string); if (env_workstring == NULL) { diff --git a/pal/src/safecrt/strlen_s.c b/pal/src/safecrt/strlen_s.c deleted file mode 100644 index 5df0b7bc13d..00000000000 --- a/pal/src/safecrt/strlen_s.c +++ /dev/null @@ -1,59 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*** -*strlen_s.c - contains strnlen() routine -* - -* -*Purpose: -* strnlen returns the length of a null-terminated string, -* not including the null byte itself, up to the specified max size -* -*******************************************************************************/ - - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -/*** -*strnlen - return the length of a null-terminated string -* -*Purpose: -* Finds the length in bytes of the given string, not including -* the final null character. Only the first maxsize characters -* are inspected: if the null character is not found, maxsize is -* returned. -* -*Entry: -* const char * str - string whose length is to be computed -* size_t maxsize -* -*Exit: -* Length of the string "str", exclusive of the final null byte, or -* maxsize if the null character is not found. -* -*Exceptions: -* -*******************************************************************************/ - -size_t __cdecl strnlen(const char *str, size_t maxsize) -{ - size_t n; - - /* Note that we do not check if str == NULL, because we do not - * return errno_t... - */ - - for (n = 0; n < maxsize && *str; n++, str++) - ; - - return n; -} -