summaryrefslogtreecommitdiff
path: root/userland/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/string')
-rw-r--r--userland/libc/string/memchr.c2
-rw-r--r--userland/libc/string/memcmp.c6
-rw-r--r--userland/libc/string/memcpy.c12
-rw-r--r--userland/libc/string/sscanf.c12
-rw-r--r--userland/libc/string/strcasecmp.c6
-rw-r--r--userland/libc/string/strchr.c8
-rw-r--r--userland/libc/string/strcmp.c6
-rw-r--r--userland/libc/string/strcspn.c2
-rw-r--r--userland/libc/string/strdup.c3
-rw-r--r--userland/libc/string/strlcpy.c6
-rw-r--r--userland/libc/string/strncasecmp.c8
-rw-r--r--userland/libc/string/strncmp.c6
-rw-r--r--userland/libc/string/strncpy.c6
-rw-r--r--userland/libc/string/strndup.c5
-rw-r--r--userland/libc/string/strnlen.c6
-rw-r--r--userland/libc/string/strpbrk.c2
-rw-r--r--userland/libc/string/strrchr.c8
-rw-r--r--userland/libc/string/strspn.c3
-rw-r--r--userland/libc/string/strstr.c10
-rw-r--r--userland/libc/string/strtok.c12
20 files changed, 82 insertions, 47 deletions
diff --git a/userland/libc/string/memchr.c b/userland/libc/string/memchr.c
index cef3bc2..0d581f4 100644
--- a/userland/libc/string/memchr.c
+++ b/userland/libc/string/memchr.c
@@ -4,7 +4,7 @@ void *memchr(const void *s, int c, size_t n) {
const char *p = s;
for (; n > 0; n--, p++) {
if (*p == c) {
- return (void*)p;
+ return (void *)p;
}
}
return NULL;
diff --git a/userland/libc/string/memcmp.c b/userland/libc/string/memcmp.c
index 01109b8..157189f 100644
--- a/userland/libc/string/memcmp.c
+++ b/userland/libc/string/memcmp.c
@@ -3,9 +3,11 @@
int memcmp(const void *s1, const void *s2, size_t n) {
int return_value = 0;
- for (uint32_t i = 0; i < n; i++)
- if (((unsigned char *)(s1))[i] != ((unsigned char *)(s2))[i])
+ 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/userland/libc/string/memcpy.c b/userland/libc/string/memcpy.c
index 7a9f01e..65f646d 100644
--- a/userland/libc/string/memcpy.c
+++ b/userland/libc/string/memcpy.c
@@ -4,15 +4,19 @@ 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)
+ for (; n >= 8; n -= 8, d += 8, s += 8) {
*(uint64_t *)d = *(uint64_t *)s;
+ }
- for (; n >= 4; n -= 4, d += 4, s += 4)
+ for (; n >= 4; n -= 4, d += 4, s += 4) {
*(uint32_t *)d = *(uint32_t *)s;
+ }
- for (; n >= 2; n -= 2, d += 2, s += 2)
+ for (; n >= 2; n -= 2, d += 2, s += 2) {
*(uint16_t *)d = *(uint16_t *)s;
- for (; n; n--)
+ }
+ for (; n; n--) {
*d++ = *s++;
+ }
return dest;
}
diff --git a/userland/libc/string/sscanf.c b/userland/libc/string/sscanf.c
index e1ede63..8a3ed0e 100644
--- a/userland/libc/string/sscanf.c
+++ b/userland/libc/string/sscanf.c
@@ -38,8 +38,9 @@ long ftnum(FILE *stream, int base, int *error) {
return 0;
}
for (;;) {
- if (EOF == (c = fgetc(stream)))
+ if (EOF == (c = fgetc(stream))) {
break;
+ }
if (c == '\0') {
ungetc(c, stream);
break;
@@ -69,13 +70,15 @@ int vfscanf(FILE *stream, const char *format, va_list ap) {
for (; *format; format++) {
if (*format != '%' && !cont) {
char c;
- if (isspace(*format))
+ if (isspace(*format)) {
continue;
+ }
if (EOF == (c = fgetc(stream))) {
break;
}
- if (*format == c) // TODO: Make sure this is the correct behaviour
+ if (*format == c) { // TODO: Make sure this is the correct behaviour
continue;
+ }
// TODO: Make sure this is the correct behaviour
errno = EINVAL;
assert(0);
@@ -164,8 +167,9 @@ size_t sscanf_read(FILE *f, unsigned char *s, size_t l) {
s++;
r++;
}
- if (!(*(c->s + c->offset)))
+ if (!(*(c->s + c->offset))) {
f->is_eof = 1;
+ }
/*
memcpy(s, c->s, l);
c->s += l;*/
diff --git a/userland/libc/string/strcasecmp.c b/userland/libc/string/strcasecmp.c
index 6420dbf..399ebc2 100644
--- a/userland/libc/string/strcasecmp.c
+++ b/userland/libc/string/strcasecmp.c
@@ -7,8 +7,9 @@ int strcasecmp(const char *s1, const char *s2) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2);) {
- if (tolower(*s1) != tolower(*s2))
+ if (tolower(*s1) != tolower(*s2)) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -23,7 +24,8 @@ int strcasecmp(const char *s1, const char *s2) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strchr.c b/userland/libc/string/strchr.c
index 1995547..179e47c 100644
--- a/userland/libc/string/strchr.c
+++ b/userland/libc/string/strchr.c
@@ -2,10 +2,12 @@
char *strchr(const char *s, int c) {
for (; *s; s++) {
- if (*s == (char)c)
- return (char*)s;
+ if (*s == (char)c) {
+ return (char *)s;
+ }
}
- if ((char)c == '\0')
+ if ((char)c == '\0') {
return (char *)s;
+ }
return NULL;
}
diff --git a/userland/libc/string/strcmp.c b/userland/libc/string/strcmp.c
index 368b8fb..b07f023 100644
--- a/userland/libc/string/strcmp.c
+++ b/userland/libc/string/strcmp.c
@@ -7,8 +7,9 @@ int strcmp(const char *s1, const char *s2) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; *s1 || *s2;) {
- if (*s1 != *s2)
+ if (*s1 != *s2) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -23,7 +24,8 @@ int strcmp(const char *s1, const char *s2) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strcspn.c b/userland/libc/string/strcspn.c
index 2ad38d5..fb5fe50 100644
--- a/userland/libc/string/strcspn.c
+++ b/userland/libc/string/strcspn.c
@@ -6,7 +6,7 @@ size_t strcspn(const char *s1, const char *s2) {
for (const char *t = s2; *t; t++) {
if (*s1 == *s2) {
r++;
- break;
+ break;
}
}
}
diff --git a/userland/libc/string/strdup.c b/userland/libc/string/strdup.c
index 9e22f94..ead535a 100644
--- a/userland/libc/string/strdup.c
+++ b/userland/libc/string/strdup.c
@@ -8,8 +8,9 @@
char *strdup(const char *s) {
size_t l = strlen(s);
char *r = malloc(l + 1);
- if (!r)
+ if (!r) {
return NULL;
+ }
strcpy(r, s);
return r;
}
diff --git a/userland/libc/string/strlcpy.c b/userland/libc/string/strlcpy.c
index a2d3dd9..041522b 100644
--- a/userland/libc/string/strlcpy.c
+++ b/userland/libc/string/strlcpy.c
@@ -7,12 +7,14 @@ size_t *strlcpy(char *s1, const char *s2, size_t n) {
size_t tmp_n = n;
const char *os2 = s2;
for (; tmp_n; tmp_n--) {
- if ((*s1++ = *s2++) == '\0')
+ if ((*s1++ = *s2++) == '\0') {
break;
+ }
}
if (tmp_n == 0) {
- if (n != 0)
+ if (n != 0) {
*s1 = '\0'; /* NUL-terminate s1 */
+ }
while (*s2++)
;
}
diff --git a/userland/libc/string/strncasecmp.c b/userland/libc/string/strncasecmp.c
index c635a03..8a7768c 100644
--- a/userland/libc/string/strncasecmp.c
+++ b/userland/libc/string/strncasecmp.c
@@ -1,6 +1,6 @@
-#include <strings.h>
#include <ctype.h>
#include <stddef.h>
+#include <strings.h>
int strncasecmp(const char *s1, const char *s2, size_t n) {
// The strcmp() function shall compare the string pointed to by s1
@@ -8,8 +8,9 @@ int strncasecmp(const char *s1, const char *s2, size_t n) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2) && n > 0; n--) {
- if (tolower(*s1) != tolower(*s2))
+ if (tolower(*s1) != tolower(*s2)) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -24,7 +25,8 @@ int strncasecmp(const char *s1, const char *s2, size_t n) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strncmp.c b/userland/libc/string/strncmp.c
index fd46189..3d6383b 100644
--- a/userland/libc/string/strncmp.c
+++ b/userland/libc/string/strncmp.c
@@ -6,8 +6,9 @@ int strncmp(const char *s1, const char *s2, size_t n) {
int l1, l2, rc;
l1 = l2 = rc = 0;
for (; (*s1 || *s2) && n > 0; n--) {
- if (*s1 != *s2)
+ if (*s1 != *s2) {
rc++;
+ }
if (*s1) {
l1++;
s1++;
@@ -22,7 +23,8 @@ int strncmp(const char *s1, const char *s2, size_t n) {
// equal to, or less than 0, if the string pointed to by s1 is
// greater than, equal to, or less than the string pointed to by
// s2, respectively.
- if (l2 > l1)
+ if (l2 > l1) {
return -rc;
+ }
return rc;
}
diff --git a/userland/libc/string/strncpy.c b/userland/libc/string/strncpy.c
index 0e88c63..fb89d38 100644
--- a/userland/libc/string/strncpy.c
+++ b/userland/libc/string/strncpy.c
@@ -4,10 +4,12 @@ char *strncpy(char *s1, const char *s2, size_t n) {
char *rc = s1;
for (; n > 0; s1++, s2++, n--) {
*s1 = *s2;
- if (!*s2)
+ if (!*s2) {
break;
+ }
}
- for (; n > 0; n--,s1++)
+ for (; n > 0; n--, s1++) {
*s1 = '\0';
+ }
return rc;
}
diff --git a/userland/libc/string/strndup.c b/userland/libc/string/strndup.c
index 22d6303..3240d97 100644
--- a/userland/libc/string/strndup.c
+++ b/userland/libc/string/strndup.c
@@ -1,7 +1,7 @@
+#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
// The strndup() function shall be equivalent to the strdup() function,
// duplicating the provided s in a new block of memory allocated as if
@@ -16,8 +16,9 @@ char *strndup(const char *s, size_t size) {
size_t l = strlen(s);
size_t real_l = min(l, size);
char *r = malloc(real_l + 1);
- if (!r)
+ if (!r) {
return NULL;
+ }
strlcpy(r, s, real_l);
return r;
}
diff --git a/userland/libc/string/strnlen.c b/userland/libc/string/strnlen.c
index 86df42e..50f907e 100644
--- a/userland/libc/string/strnlen.c
+++ b/userland/libc/string/strnlen.c
@@ -2,8 +2,10 @@
size_t strnlen(const char *s, size_t maxlen) {
size_t i;
- for (i = 0; i < maxlen; i++)
- if (s[i] == 0)
+ for (i = 0; i < maxlen; i++) {
+ if (s[i] == 0) {
break;
+ }
+ }
return i;
}
diff --git a/userland/libc/string/strpbrk.c b/userland/libc/string/strpbrk.c
index 3bb058b..cbe51de 100644
--- a/userland/libc/string/strpbrk.c
+++ b/userland/libc/string/strpbrk.c
@@ -4,7 +4,7 @@ char *strpbrk(const char *s1, const char *s2) {
for (; *s1; s1++) {
for (const char *t = s2; *t; t++) {
if (*s1 == *t) {
- return (char*)s1;
+ return (char *)s1;
}
}
}
diff --git a/userland/libc/string/strrchr.c b/userland/libc/string/strrchr.c
index a44199a..30b625d 100644
--- a/userland/libc/string/strrchr.c
+++ b/userland/libc/string/strrchr.c
@@ -3,10 +3,12 @@
char *strrchr(const char *s, int c) {
char *last = NULL;
for (; *s; s++) {
- if (*s == (char)c)
+ if (*s == (char)c) {
last = (char *)s;
+ }
+ }
+ if ((char)c == '\0') {
+ last = (char *)s;
}
- if ((char)c == '\0')
- last = (char*)s;
return last;
}
diff --git a/userland/libc/string/strspn.c b/userland/libc/string/strspn.c
index 2a7d3ae..d6b1595 100644
--- a/userland/libc/string/strspn.c
+++ b/userland/libc/string/strspn.c
@@ -10,8 +10,9 @@ size_t strspn(const char *s1, const char *s2) {
break;
}
}
- if (!e)
+ if (!e) {
break;
+ }
r++;
}
return r;
diff --git a/userland/libc/string/strstr.c b/userland/libc/string/strstr.c
index 9de0954..4300f24 100644
--- a/userland/libc/string/strstr.c
+++ b/userland/libc/string/strstr.c
@@ -2,8 +2,9 @@
char *strstr(const char *s1, const char *s2) {
// If s2 points to a string with zero length, the function shall return s1.
- if ('\0' == *s2)
- return (char*)s1;
+ if ('\0' == *s2) {
+ return (char *)s1;
+ }
for (; *s1; s1++) {
const char *t1 = s1;
const char *t2 = s2;
@@ -14,8 +15,9 @@ char *strstr(const char *s1, const char *s2) {
break;
}
}
- if (!is_dif)
- return (char*)s1;
+ if (!is_dif) {
+ return (char *)s1;
+ }
}
return NULL;
}
diff --git a/userland/libc/string/strtok.c b/userland/libc/string/strtok.c
index 7b8d0e3..a4a9d0f 100644
--- a/userland/libc/string/strtok.c
+++ b/userland/libc/string/strtok.c
@@ -7,18 +7,20 @@ char *strtok(char *restrict s, const char *restrict sep) {
strtok_s = s;
return strtok(NULL, sep);
}
- if(!strtok_s)
- return NULL;
+ if (!strtok_s) {
+ return NULL;
+ }
char *e = strpbrk(strtok_s, sep);
if (!e) {
- char *r = strtok_s;
- strtok_s = NULL;
+ char *r = strtok_s;
+ strtok_s = NULL;
return r;
}
*e = '\0';
e--;
- for (; *sep; sep++)
+ for (; *sep; sep++) {
e++;
+ }
e++;
char *r = strtok_s;
strtok_s = e;