summaryrefslogtreecommitdiff
path: root/lib/libc/string
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
parent8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff)
feat: add gzip and new headers
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/memcpy.c39
-rw-r--r--lib/libc/string/strxfrm.c4
2 files changed, 41 insertions, 2 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;
+}
diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c
index 123ebfe8..d216733b 100644
--- a/lib/libc/string/strxfrm.c
+++ b/lib/libc/string/strxfrm.c
@@ -6,13 +6,13 @@ size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n)
size_t len = strlen(s2);
if (n > len)
- strcpy(s1, s2);
+ strlcpy(s1, s2, n);
return len;
}
__weak size_t strxfrm_l(char *restrict s1, const char *restrict s2, size_t n,
- locale_t __unused locale)
+ locale_t __unused locale)
{
return strxfrm(s1, s2, n);
}