summaryrefslogtreecommitdiff
path: root/kernel/libc/string
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-02-21 00:14:29 +0100
committerAnton Kling <anton@kling.gg>2024-02-21 00:14:29 +0100
commit8ff63b062d724826d8017504063df9b92f8e6703 (patch)
tree03bf0b5a278a4908da8912f956e5651bea9412f1 /kernel/libc/string
parenta85eacdd2406fede4d6ff5cb130b1758978cabb3 (diff)
New clang-format options
Diffstat (limited to 'kernel/libc/string')
-rw-r--r--kernel/libc/string/copy.c9
-rw-r--r--kernel/libc/string/isequal.c12
-rw-r--r--kernel/libc/string/memcmp.c6
-rw-r--r--kernel/libc/string/memcpy.c12
-rw-r--r--kernel/libc/string/memset.c3
-rw-r--r--kernel/libc/string/strlcpy.c6
6 files changed, 32 insertions, 16 deletions
diff --git a/kernel/libc/string/copy.c b/kernel/libc/string/copy.c
index 277c808..166924b 100644
--- a/kernel/libc/string/copy.c
+++ b/kernel/libc/string/copy.c
@@ -6,21 +6,24 @@
char *copy_and_allocate_string(const char *s) {
size_t l = strlen(s);
char *r = kmalloc(l + 1);
- if (!r)
+ 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))
+ 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)
+ if (!r) {
return NULL;
+ }
strlcpy(r, s, len);
return r;
}
diff --git a/kernel/libc/string/isequal.c b/kernel/libc/string/isequal.c
index 90712db..c3dbebb 100644
--- a/kernel/libc/string/isequal.c
+++ b/kernel/libc/string/isequal.c
@@ -1,15 +1,19 @@
#include "../include/string.h"
int isequal(const char *s1, const char *s2) {
- for (; *s1; s1++, s2++)
- if (*s1 != *s2)
+ for (; *s1; s1++, s2++) {
+ if (*s1 != *s2) {
return 0;
+ }
+ }
return 1;
}
int isequal_n(const char *s1, const char *s2, u32 n) {
- for (; *s1 && n; s1++, s2++, n--)
- if (*s1 != *s2)
+ for (; *s1 && n; s1++, s2++, n--) {
+ if (*s1 != *s2) {
return 0;
+ }
+ }
return 1;
}
diff --git a/kernel/libc/string/memcmp.c b/kernel/libc/string/memcmp.c
index deeb029..5631d05 100644
--- a/kernel/libc/string/memcmp.c
+++ b/kernel/libc/string/memcmp.c
@@ -3,9 +3,11 @@
int memcmp(const void *s1, const void *s2, u32 n) {
int return_value = 0;
- for (u32 i = 0; i < n; i++)
- if (((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i])
+ for (u32 i = 0; i < n; i++) {
+ if (((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i]) {
return_value++;
+ }
+ }
return return_value;
}
diff --git a/kernel/libc/string/memcpy.c b/kernel/libc/string/memcpy.c
index 8b03536..ac7a57b 100644
--- a/kernel/libc/string/memcpy.c
+++ b/kernel/libc/string/memcpy.c
@@ -4,16 +4,20 @@ void *memcpy(void *dest, const void *src, u32 n) {
unsigned char *d = dest;
const unsigned char *s = src;
- for (; n >= 8; n -= 8, d += 8, s += 8)
+ for (; n >= 8; n -= 8, d += 8, s += 8) {
*(u64 *)d = *(u64 *)s;
+ }
- for (; n >= 4; n -= 4, d += 4, s += 4)
+ for (; n >= 4; n -= 4, d += 4, s += 4) {
*(u32 *)d = *(u32 *)s;
+ }
- for (; n >= 2; n -= 2, d += 2, s += 2)
+ for (; n >= 2; n -= 2, d += 2, s += 2) {
*(u16 *)d = *(u16 *)s;
+ }
- for (; n; n--)
+ for (; n; n--) {
*d++ = *s++;
+ }
return dest;
}
diff --git a/kernel/libc/string/memset.c b/kernel/libc/string/memset.c
index 5d7de62..34fd507 100644
--- a/kernel/libc/string/memset.c
+++ b/kernel/libc/string/memset.c
@@ -2,8 +2,9 @@
void *memset(void *dst, const unsigned char c, u32 n) {
uintptr_t d = (uintptr_t)dst;
- for (u32 i = 0; i < n; i++, d++)
+ for (u32 i = 0; i < n; i++, d++) {
*(unsigned char *)d = c;
+ }
return (void *)d;
}
diff --git a/kernel/libc/string/strlcpy.c b/kernel/libc/string/strlcpy.c
index 43d0e58..1338699 100644
--- a/kernel/libc/string/strlcpy.c
+++ b/kernel/libc/string/strlcpy.c
@@ -8,12 +8,14 @@ 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')
+ if ((*dst++ = *src++) == '\0') {
break;
+ }
}
if (n == 0) {
- if (dsize != 0)
+ if (dsize != 0) {
*dst = '\0'; /* NUL-terminate dst */
+ }
while (*src++)
;
}