aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/string.c
diff options
context:
space:
mode:
authorMarvin Borner2019-10-17 20:38:19 +0200
committerMarvin Borner2019-10-17 20:38:19 +0200
commit17c6b30949ce7d4a293862ec8f9b873e17fe0cd8 (patch)
treee87380859d68848ef2a5d7eaa28f29100bcab296 /src/kernel/lib/string.c
parentbf17b4720b06f6045934e3eb2e2e9c808ead8155 (diff)
Optimized string functions
Diffstat (limited to 'src/kernel/lib/string.c')
-rw-r--r--src/kernel/lib/string.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/kernel/lib/string.c b/src/kernel/lib/string.c
index 1e41d15..11e6021 100644
--- a/src/kernel/lib/string.c
+++ b/src/kernel/lib/string.c
@@ -8,29 +8,22 @@ size_t strlen(const char *str) {
}
size_t strcmp(const char *s1, const char *s2) {
- while (*s1 && (*s1 == *s2)) {
- s1++;
- s2++;
- }
- return *(const unsigned char *) s1 - *(const unsigned char *) s2;
+ size_t s_a = strlen(s1);
+ for (size_t i = 0; i < s_a; i++) if (s1[i] != s2[i]) return 1;
+ return 0;
}
-char *strcat(char *dest, const char *src) {
- unsigned int i = 0;
- unsigned int j = 0;
- for (i = 0; dest[i] != 0; i++) {}
- for (j = 0; src[j] != 0; j++) {
- dest[i + j] = src[j];
- }
- dest[i + j] = 0;
- return dest;
+void strcat(char *dest, const char *src) {
+ size_t s_dest = strlen(dest);
+ size_t s_orig = strlen(src);
+
+ for (size_t i = 0; i < s_orig; i++) dest[s_dest + i] = src[i];
+ dest[s_dest + s_orig] = 0;
}
-char *strcpy(char *dest, const char *src) {
- unsigned int i = 0;
- for (i = 0; src[i] != 0; i++) {
- dest[i] = src[i];
- }
- dest[i] = 0;
- return dest;
+void strcpy(char *dest, const char *src) {
+ size_t s_orig = strlen(src);
+
+ for (size_t i = 0; i < s_orig; i++) dest[i] = src[i];
+ dest[s_orig] = 0;
}