PatchworkOS
Loading...
Searching...
No Matches
memmove_s.c
Go to the documentation of this file.
2#include <errno.h>
3#include <stdint.h>
4#include <stdlib.h>
5#include <string.h>
6
8
9errno_t memmove_s(void* s1, rsize_t s1max, const void* 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 if (s1 != NULL && s1max <= RSIZE_MAX)
17 {
18 memset(s1, 0, s1max);
19 }
20
22 return EINVAL;
23 }
24
25 while (n)
26 {
27 if (dest == s2 || src == s1)
28 {
29 src += n;
30 dest += n;
31
32 while (n--)
33 {
34 *--dest = *--src;
35 }
36
37 return 0;
38 }
39
40 *dest++ = *src++;
41 --n;
42 }
43
44 return 0;
45}
constraint_handler_t _constraintHandler
#define _CONSTRAINT_VIOLATION(e)
int errno_t
Definition errno_t.h:4
#define EINVAL
Invalid argument.
Definition errno.h:142
#define NULL
Pointer error value.
Definition NULL.h:23
errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n)
Definition memmove_s.c:9
__SIZE_TYPE__ rsize_t
Definition rsize_t.h:4
_PUBLIC void * memset(void *s, int c, size_t n)
Definition memset.c:4