summaryrefslogtreecommitdiff
path: root/libc/string
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-30 22:12:14 +0100
committerAnton Kling <anton@kling.gg>2023-10-31 00:18:38 +0100
commit8a9208612eec8ddae4c418485d848ecfa0613699 (patch)
tree2f4b29200c2f0c19ae52f45bdb9b38a41b356e30 /libc/string
parentca76600acc8bf7a02346efa5bd8f17072210ec01 (diff)
Meta: Move kernel and userland to their own folders.
This is to allow both the kernel and the userland to share certain header files and to make the folder structure a bit more clear.
Diffstat (limited to 'libc/string')
-rw-r--r--libc/string/copy.c26
-rw-r--r--libc/string/isequal.c15
-rw-r--r--libc/string/memcmp.c12
-rw-r--r--libc/string/memcpy.c20
-rw-r--r--libc/string/memset.c9
-rw-r--r--libc/string/strcat.c6
-rw-r--r--libc/string/strcmp.c8
-rw-r--r--libc/string/strcpy.c8
-rw-r--r--libc/string/strlcpy.c21
-rw-r--r--libc/string/strlen.c8
-rw-r--r--libc/string/strncpy.c11
11 files changed, 0 insertions, 144 deletions
diff --git a/libc/string/copy.c b/libc/string/copy.c
deleted file mode 100644
index 277c808..0000000
--- a/libc/string/copy.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <assert.h>
-#include <kmalloc.h>
-#include <stddef.h>
-#include <string.h>
-
-char *copy_and_allocate_string(const char *s) {
- size_t l = strlen(s);
- char *r = kmalloc(l + 1);
- if (!r)
- return NULL;
- return strncpy(r, s, l);
-}
-
-char *copy_and_allocate_user_string(const char *s) {
- size_t len;
- if (!is_valid_user_c_string(s, &len))
- return NULL;
- size_t real_len = strlen(s);
- assert(real_len == len);
- len = real_len;
- char *r = kmalloc(len + 1);
- if (!r)
- return NULL;
- strlcpy(r, s, len);
- return r;
-}
diff --git a/libc/string/isequal.c b/libc/string/isequal.c
deleted file mode 100644
index cdbd3cc..0000000
--- a/libc/string/isequal.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "../include/string.h"
-
-int isequal(const char *s1, const char *s2) {
- for(;*s1;s1++,s2++)
- if(*s1 != *s2)
- return 0;
- return 1;
-}
-
-int isequal_n(const char *s1, const char *s2, uint32_t n) {
- for(;*s1 && n;s1++,s2++,n--)
- if(*s1 != *s2)
- return 0;
- return 1;
-}
diff --git a/libc/string/memcmp.c b/libc/string/memcmp.c
deleted file mode 100644
index 72c680a..0000000
--- a/libc/string/memcmp.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "../include/string.h"
-
-int memcmp(const void *s1, const void *s2, uint32_t n)
-{
- int return_value = 0;
-
- for(uint32_t i = 0;i < n;i++)
- if(((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i])
- return_value++;
-
- return return_value;
-}
diff --git a/libc/string/memcpy.c b/libc/string/memcpy.c
deleted file mode 100644
index 5c04407..0000000
--- a/libc/string/memcpy.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "../include/string.h"
-
-void *
-memcpy(void *dest, const void *src, uint32_t n) {
- unsigned char *d = dest;
- const unsigned char *s = src;
-
- for (; n >= 8; n -= 8, d += 8, s += 8)
- *(uint64_t *)d = *(uint64_t *)s;
-
- for (; n >= 4; n -= 4, d += 4, s += 4)
- *(uint32_t *)d = *(uint32_t *)s;
-
- for (; n >= 2; n -= 2, d += 2, s += 2)
- *(uint16_t *)d = *(uint16_t *)s;
-
- for (; n; n--)
- *d++ = *s++;
- return dest;
-}
diff --git a/libc/string/memset.c b/libc/string/memset.c
deleted file mode 100644
index a446eb4..0000000
--- a/libc/string/memset.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-
-void *memset(void *dst, const unsigned char c, uint32_t n) {
- uintptr_t d = (uintptr_t)dst;
- for (uint32_t i = 0; i < n; i++, d++)
- *(unsigned char *)d = c;
-
- return (void *)d;
-}
diff --git a/libc/string/strcat.c b/libc/string/strcat.c
deleted file mode 100644
index 78a9ec6..0000000
--- a/libc/string/strcat.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <string.h>
-
-char *strcat(char *s1, const char *s2) {
- strcpy(s1 + strlen(s1), s2);
- return s1;
-}
diff --git a/libc/string/strcmp.c b/libc/string/strcmp.c
deleted file mode 100644
index d7039e2..0000000
--- a/libc/string/strcmp.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "../include/string.h"
-
-int strcmp(const char *s1, const char *s2)
-{
- for(;*s1 == *s2 && *s1; s1++, s2++)
- ;
- return *s1 - *s2;
-}
diff --git a/libc/string/strcpy.c b/libc/string/strcpy.c
deleted file mode 100644
index fa1e336..0000000
--- a/libc/string/strcpy.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <string.h>
-
-char *strcpy(char *d, const char *s) {
- char *s1 = d;
- for (; (*d++ = *s++);)
- ;
- return s1;
-}
diff --git a/libc/string/strlcpy.c b/libc/string/strlcpy.c
deleted file mode 100644
index 43d0e58..0000000
--- a/libc/string/strlcpy.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <stddef.h>
-#include <string.h>
-
-// Copy string src to buffer dst of size dsize. At most dsize-1
-// chars will be copied. Always NUL terminates (unless dsize == 0).
-// Returns strlen(src); if retval >= dsize, truncation occurred.
-size_t strlcpy(char *dst, const char *src, size_t dsize) {
- size_t n = dsize;
- const char *osrc = src;
- for (; n; n--) {
- if ((*dst++ = *src++) == '\0')
- break;
- }
- if (n == 0) {
- if (dsize != 0)
- *dst = '\0'; /* NUL-terminate dst */
- while (*src++)
- ;
- }
- return src - osrc - 1;
-}
diff --git a/libc/string/strlen.c b/libc/string/strlen.c
deleted file mode 100644
index 4346383..0000000
--- a/libc/string/strlen.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "../include/string.h"
-
-unsigned long strlen(const char *s)
-{
- const char * tmp = s;
- for(;*tmp++;);
- return (tmp - s)-1;
-}
diff --git a/libc/string/strncpy.c b/libc/string/strncpy.c
deleted file mode 100644
index a886895..0000000
--- a/libc/string/strncpy.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <stddef.h>
-#include <string.h>
-
-// FIXME: Something is weird with this function
-char *strncpy(char *dest, const char *src, size_t n) {
- char *r = dest;
- for (; n && (*dest = *src); n--, src++, dest++)
- ;
- *dest = '\0';
- return r;
-}