PatchworkOS
Loading...
Searching...
No Matches
memcpy_s.c
Go to the documentation of this file.
1
#include "
common/use_annex_k.h
"
2
#include <
errno.h
>
3
#include <
stdint.h
>
4
#include <
stdlib.h
>
5
#include <
string.h
>
6
7
#include "
common/constraint_handler.h
"
8
9
errno_t
memcpy_s
(
void
*
_RESTRICT
s1,
rsize_t
s1max,
const
void
*
_RESTRICT
s2,
rsize_t
n)
10
{
11
char
* dest = (
char
*)s1;
12
const
char
* src = (
const
char
*)s2;
13
14
if
(s1 !=
NULL
&& s2 !=
NULL
&& s1max <= RSIZE_MAX && n <= RSIZE_MAX && n <= s1max)
15
{
16
while
(n--)
17
{
18
if
(dest == s2 || src == s1)
19
{
20
goto
runtime_constraint_violation;
21
}
22
23
*dest++ = *src++;
24
}
25
26
return
0;
27
}
28
29
runtime_constraint_violation:
30
31
if
(s1 !=
NULL
&& s1max <= RSIZE_MAX)
32
{
33
memset
(s1, 0, s1max);
34
}
35
36
_constraintHandler
(
_CONSTRAINT_VIOLATION
(
EINVAL
));
37
return
EINVAL
;
38
}
_constraintHandler
constraint_handler_t _constraintHandler
Definition
constraint_handler.c:3
constraint_handler.h
_CONSTRAINT_VIOLATION
#define _CONSTRAINT_VIOLATION(e)
Definition
constraint_handler.h:10
errno.h
errno_t
int errno_t
Definition
errno_t.h:4
EINVAL
#define EINVAL
Invalid argument.
Definition
errno.h:142
NULL
#define NULL
Pointer error value.
Definition
NULL.h:23
_RESTRICT
#define _RESTRICT
Definition
config.h:17
memcpy_s
errno_t memcpy_s(void *_RESTRICT s1, rsize_t s1max, const void *_RESTRICT s2, rsize_t n)
Definition
memcpy_s.c:9
rsize_t
__SIZE_TYPE__ rsize_t
Definition
rsize_t.h:4
stdint.h
stdlib.h
string.h
memset
_PUBLIC void * memset(void *s, int c, size_t n)
Definition
memset.c:4
use_annex_k.h
src
libstd
functions
string
memcpy_s.c
Generated by
1.9.8