mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[winpr,string] add wcsndup
This commit is contained in:
@@ -427,9 +427,23 @@ extern "C"
|
||||
WINPR_API INT64 GetLine(char** lineptr, size_t* size, FILE* stream);
|
||||
|
||||
#if !defined(WINPR_HAVE_STRNDUP)
|
||||
WINPR_ATTR_MALLOC(free, 1)
|
||||
WINPR_API char* strndup(const char* s, size_t n);
|
||||
#endif
|
||||
|
||||
/** @brief WCHAR version of \b strndup
|
||||
* creates a copy of a \b WCHAR string of \b n characters length. The copy will always be \b \0
|
||||
* terminated
|
||||
*
|
||||
* @param s The \b WCHAR string to copy
|
||||
* @param n The numer of WCHAR to copy
|
||||
*
|
||||
* @return An allocated copy of \b s, always \b \0 terminated
|
||||
* @since version 3.10.0
|
||||
*/
|
||||
WINPR_ATTR_MALLOC(free, 1)
|
||||
WINPR_API WCHAR* wcsndup(const WCHAR* s, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -834,3 +834,15 @@ const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t
|
||||
(void)ConvertUtf8ToWChar(str, buffer, len);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
WCHAR* wcsndup(const WCHAR* s, size_t n)
|
||||
{
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
WCHAR* copy = calloc(n + 1, sizeof(WCHAR));
|
||||
if (!copy)
|
||||
return NULL;
|
||||
memcpy(copy, s, n * sizeof(WCHAR));
|
||||
return copy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user