ReactOS 0.4.16-dev-853-g88d9285
corecrt_memcpy_s.h
Go to the documentation of this file.
1//
2// corecrt_memcpy_s.h
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Inline definitions of memcpy_s and memmove_s
7//
8#pragma once
9
10#include <corecrt.h>
11#include <errno.h>
12#include <vcruntime_string.h>
13
14#pragma warning(push)
15#pragma warning(disable: _UCRT_DISABLED_WARNINGS)
17
19
20#ifndef _CRT_MEMCPY_S_INLINE
21 #define _CRT_MEMCPY_S_INLINE static __inline
22#endif
23
24#define _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(expr, errorcode) \
25 { \
26 int _Expr_val=!!(expr); \
27 if (!(_Expr_val)) \
28 { \
29 errno = errorcode; \
30 _invalid_parameter_noinfo(); \
31 return errorcode; \
32 } \
33 }
34
35#if !defined RC_INVOKED && !defined __midl && __STDC_WANT_SECURE_LIB__
36
37 _Success_(return == 0)
40 _Out_writes_bytes_to_opt_(_DestinationSize, _SourceSize) void* const _Destination,
41 _In_ rsize_t const _DestinationSize,
42 _In_reads_bytes_opt_(_SourceSize) void const* const _Source,
43 _In_ rsize_t const _SourceSize
44 )
45 {
46 if (_SourceSize == 0)
47 {
48 return 0;
49 }
50
52 if (_Source == NULL || _DestinationSize < _SourceSize)
53 {
54 memset(_Destination, 0, _DestinationSize);
55
57 _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(_DestinationSize >= _SourceSize, ERANGE);
58
59 // Unreachable, but required to suppress /analyze warnings:
60 return EINVAL;
61 }
62 memcpy(_Destination, _Source, _SourceSize);
63 return 0;
64 }
65
68 _Out_writes_bytes_to_opt_(_DestinationSize, _SourceSize) void* const _Destination,
69 _In_ rsize_t const _DestinationSize,
70 _In_reads_bytes_opt_(_SourceSize) void const* const _Source,
71 _In_ rsize_t const _SourceSize
72 )
73 {
74 if (_SourceSize == 0)
75 {
76 return 0;
77 }
78
81 _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(_DestinationSize >= _SourceSize, ERANGE);
82
83 memmove(_Destination, _Source, _SourceSize);
84 return 0;
85 }
86
87#endif
88
89#undef _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE
90
92#pragma warning(pop) // _UCRT_DISABLED_WARNINGS
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
#define _CRT_MEMCPY_S_INLINE
#define _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(expr, errorcode)
_Source
_Destination
#define NULL
Definition: types.h:112
size_t rsize_t
Definition: stubs.c:780
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define _Success_(c)
Definition: no_sal2.h:84
#define _In_
Definition: no_sal2.h:158
#define _Out_writes_bytes_to_opt_(s, c)
Definition: no_sal2.h:240
#define _In_reads_bytes_opt_(s)
Definition: no_sal2.h:224
int CDECL memmove_s(void *dest, size_t numberOfElements, const void *src, size_t count)
Definition: heap.c:757
int CDECL memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count)
Definition: heap.c:800
#define memset(x, y, z)
Definition: compat.h:39
#define _Check_return_opt_
Definition: corecrt.h:224
#define _UCRT_DISABLE_CLANG_WARNINGS
Definition: corecrt.h:109
#define _UCRT_RESTORE_CLANG_WARNINGS
Definition: corecrt.h:117
#define _Check_return_wat_
Definition: corecrt.h:230
int errno_t
Definition: corecrt.h:615
#define _CRT_END_C_HEADER
Definition: vcruntime.h:42
#define _CRT_BEGIN_C_HEADER
Definition: vcruntime.h:40
#define __CRTDECL
Definition: yvals.h:17
#define const
Definition: zconf.h:233