STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
15 
16 #ifndef _CRT_MEMCPY_S_INLINE
17  #define _CRT_MEMCPY_S_INLINE static __inline
18 #endif
19 
20 #define _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(expr, errorcode) \
21  { \
22  int _Expr_val=!!(expr); \
23  if (!(_Expr_val)) \
24  { \
25  errno = errorcode; \
26  _invalid_parameter_noinfo(); \
27  return errorcode; \
28  } \
29  }
30 
31 #if !defined RC_INVOKED && !defined __midl && __STDC_WANT_SECURE_LIB__
32 
33  _Success_(return == 0)
37  _In_ rsize_t const _DestinationSize,
38  _In_reads_bytes_opt_(_SourceSize) void const* const _Source,
40  )
41  {
42  if (_SourceSize == 0)
43  {
44  return 0;
45  }
46 
48  if (_Source == NULL || _DestinationSize < _SourceSize)
49  {
50  memset(_Destination, 0, _DestinationSize);
51 
53  _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(_DestinationSize >= _SourceSize, ERANGE);
54 
55  // Unreachable, but required to suppress /analyze warnings:
56  return EINVAL;
57  }
58 
59  memcpy(_Destination, _Source, _SourceSize);
60  return 0;
61  }
62 
65  _Out_writes_bytes_to_opt_(_DestinationSize, _SourceSize) void* const _Destination,
66  _In_ rsize_t const _DestinationSize,
67  _In_reads_bytes_opt_(_SourceSize) void const* const _Source,
68  _In_ rsize_t const _SourceSize
69  )
70  {
71  if (_SourceSize == 0)
72  {
73  return 0;
74  }
75 
78  _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(_DestinationSize >= _SourceSize, ERANGE);
79 
80  memmove(_Destination, _Source, _SourceSize);
81  return 0;
82  }
83 
84 #endif
85 
86 #undef _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE
87 
_Check_return_wat_ _CRT_MEMCPY_S_INLINE errno_t __CRTDECL memmove_s(_Out_writes_bytes_to_opt_(_DestinationSize, _SourceSize) void *const _Destination, _In_ rsize_t const _DestinationSize, _In_reads_bytes_opt_(_SourceSize) void const *const _Source, _In_ rsize_t const _SourceSize)
Definition: corecrt_memcpy_s.h:64
_VCRTIMP void *__cdecl memmove(_Out_writes_bytes_all_opt_(_Size) void *_Dst, _In_reads_bytes_opt_(_Size) void const *_Src, _In_ size_t _Size)
_SourceSize void *const _Destination
Definition: corecrt_memcpy_s.h:36
#define EINVAL
Definition: errno.h:73
#define _Check_return_opt_
Definition: corecrt.h:96
#define _CRT_MEMCPY_S_VALIDATE_RETURN_ERRCODE(expr, errorcode)
Definition: corecrt_memcpy_s.h:20
int errno_t
Definition: corecrt.h:476
#define _Check_return_wat_
Definition: corecrt.h:102
size_t rsize_t
Definition: corecrt.h:527
_Success_(return==0) _Check_return_opt_ _CRT_MEMCPY_S_INLINE errno_t __CRTDECL memcpy_s(_Out_writes_bytes_to_opt_(_DestinationSize
#define _CRT_BEGIN_C_HEADER
Definition: vcruntime.h:73
#define __CRTDECL
Definition: vcruntime.h:156
#define ERANGE
Definition: errno.h:74
_SourceSize void *const _In_ rsize_t const _DestinationSize
Definition: corecrt_memcpy_s.h:36
#define _In_
Definition: sal.h:305
_Source
Definition: corecrt_wstring.h:187
_SourceSize void *const _In_ rsize_t const _In_ rsize_t const _SourceSize
Definition: corecrt_memcpy_s.h:41
_Pre_maybenull_ _In_ _Inout_opt_ mbstate_t _State _Out_writes_bytes_to_opt_(_SizeInBytes,*_Retval) char *_Dst
_SourceSize void *const _In_ rsize_t const _In_reads_bytes_opt_(_SourceSize) void const *const _Source
memcpy(_Destination, _Source, _SourceSize)
#define _CRT_END_C_HEADER
Definition: vcruntime.h:76
#define _CRT_MEMCPY_S_INLINE
Definition: corecrt_memcpy_s.h:17
#define NULL
Definition: corecrt.h:158