Reactos
1//
2// wmemcpy_s.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines wmemcpy_s(), which copies wide characters from a source buffer to a
7// destination buffer. Overlapping buffers are not treated specially, so
8// propagation may occur. If propagation must be avoided, wmemmove_s() must be
9// used.
10//
11// Returns 0 if successful; an error code on failure.
12//
13#include <corecrt_internal.h>
14#include <wchar.h>
15
16
17
18extern "C" errno_t __cdecl wmemcpy_s(
19 wchar_t* const destination,
20 size_t const size_in_elements,
21 wchar_t const* const source,
22 size_t const count
23 )
24{
25 if (count == 0)
26 return 0;
27
28 _VALIDATE_RETURN_ERRCODE(destination != nullptr, EINVAL);
29
30 if (source == nullptr || size_in_elements < count)
31 {
32 // Zero the destination buffer:
33 wmemset(destination, 0, size_in_elements);
34
35 _VALIDATE_RETURN_ERRCODE(source != nullptr, EINVAL);
36 _VALIDATE_RETURN_ERRCODE(size_in_elements >= count, ERANGE);
37
38 // Useless, but prefast is confused:
39 return EINVAL;
40 }
41
42#pragma warning(suppress:__WARNING_BANNED_API_USAGEL2) /* 28726 */
43 wmemcpy(destination, source, count);
44 return 0;
45}