mirror of
https://github.com/reactos/reactos.git
synced 2025-08-11 13:45:40 +00:00
[UCRT] Import Microsoft.Windows.SDK.CRTSource version 10.0.22621.3
Imported from https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource/10.0.22621.3 License: MIT
This commit is contained in:
parent
f1b60c66f0
commit
04e0dc4a7a
568 changed files with 115483 additions and 0 deletions
60
sdk/lib/ucrt/string/wcsdup.cpp
Normal file
60
sdk/lib/ucrt/string/wcsdup.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// wcsdup.cpp
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Defines _wcsdup() and _wcsdup_dbg(), which dynamically allocate a buffer and
|
||||
// duplicate a string into it.
|
||||
//
|
||||
// These functions allocate storage via malloc() or _malloc_dbg(). The caller
|
||||
// is responsible for free()ing the returned array. If the input string is null
|
||||
// or if sufficient memory could not be allocated, these functions return null.
|
||||
//
|
||||
#include <corecrt_internal.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
extern "C" wchar_t* __cdecl _wcsdup(wchar_t const* const string)
|
||||
{
|
||||
return _wcsdup_dbg(string, _NORMAL_BLOCK, nullptr, 0);
|
||||
}
|
||||
|
||||
extern "C" wchar_t* __cdecl _wcsdup_dbg(
|
||||
wchar_t const* const string,
|
||||
int const block_use,
|
||||
char const* const file_name,
|
||||
int const line_number
|
||||
)
|
||||
|
||||
#else // ^^^ _DEBUG ^^^ // vvv !_DEBUG vvv //
|
||||
|
||||
extern "C" wchar_t* __cdecl _wcsdup(
|
||||
wchar_t const* string
|
||||
)
|
||||
|
||||
#endif // !_DEBUG
|
||||
{
|
||||
if (string == nullptr)
|
||||
return nullptr;
|
||||
|
||||
size_t const size_in_elements = wcslen(string) + 1;
|
||||
|
||||
#ifdef _DEBUG
|
||||
wchar_t* const memory = static_cast<wchar_t*>(_malloc_dbg(
|
||||
size_in_elements * sizeof(wchar_t),
|
||||
block_use,
|
||||
file_name,
|
||||
line_number));
|
||||
#else
|
||||
wchar_t* const memory = static_cast<wchar_t*>(malloc(
|
||||
size_in_elements * sizeof(wchar_t)));
|
||||
#endif
|
||||
|
||||
if (memory == nullptr)
|
||||
return nullptr;
|
||||
|
||||
_ERRCHECK(wcscpy_s(memory, size_in_elements, string));
|
||||
return memory;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue