summaryrefslogtreecommitdiff
path: root/lib/libc/string/memcpy.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
commit885f5974cdf65b59415837ae97f5a14ef1350670 (patch)
tree66ac13de29c7f4932c5fcae11773df574e4e256a /lib/libc/string/memcpy.c
parent8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff)
feat: add gzip and new headers
Diffstat (limited to 'lib/libc/string/memcpy.c')
-rw-r--r--lib/libc/string/memcpy.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c
index ecdbd602..05586b55 100644
--- a/lib/libc/string/memcpy.c
+++ b/lib/libc/string/memcpy.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <string.h>
#include <features.h>
@@ -14,3 +15,41 @@ void *memcpy(void *restrict s1, const void *restrict s2, size_t n)
return s1;
}
+
+errno_t memcpy_s(void *restrict dest, rsize_t destsz, const void *restrict src,
+ rsize_t count)
+{
+ if (dest == NULL || src == NULL) {
+ if (dest != NULL && destsz > 0) {
+ unsigned char *d = dest;
+ for (rsize_t i = 0; i < destsz; i++) {
+ d[i] = 0;
+ }
+ }
+
+ return EINVAL;
+ }
+
+ const unsigned char *s = src;
+ unsigned char *d = dest;
+
+ if ((d > s && d < s + count) || (s > d && s < d + count)) {
+ for (rsize_t i = 0; i < destsz; i++) {
+ d[i] = 0;
+ }
+ return EINVAL;
+ }
+
+ if (count > destsz) {
+ for (rsize_t i = 0; i < destsz; i++) {
+ d[i] = 0;
+ }
+ return ERANGE;
+ }
+
+ for (rsize_t i = 0; i < count; i++) {
+ d[i] = s[i];
+ }
+
+ return 0;
+}