libc/string: Minor improvements - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 0f61a6528784b5add0eef1d64ea16eb5adf689f9
DIR parent 9a60d2a80efcd85c85f90b1c0406c8fe3f324f5b
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sun, 4 Jan 2026 20:48:34 +0100
libc/string: Minor improvements
Diffstat:
M src/libc/string/strcat.c | 7 +++----
M src/libc/string/strchr.c | 3 +--
M src/libc/string/strcoll.c | 4 +---
M src/libc/string/strncat.c | 7 +++----
M src/libc/string/strrchr.c | 6 +++---
M src/libc/string/strstr.c | 2 +-
6 files changed, 12 insertions(+), 17 deletions(-)
---
DIR diff --git a/src/libc/string/strcat.c b/src/libc/string/strcat.c
@@ -5,11 +5,10 @@
char *
strcat(char *restrict s1, const char *restrict s2)
{
- char *ret = s1;
-
- while (*s1)
- ++s1;
+ char *ret;
+ for (ret = s1; *s1; ++s1)
+ ;
while ((*s1++ = *s2++) != 0)
;
DIR diff --git a/src/libc/string/strchr.c b/src/libc/string/strchr.c
@@ -7,6 +7,5 @@ strchr(const char *s, int c)
{
while (*s && *s != c)
++s;
-
- return (*s == c) ? (char *) s : NULL;
+ return *s ? (char *) s : NULL;
}
DIR diff --git a/src/libc/string/strcoll.c b/src/libc/string/strcoll.c
@@ -5,7 +5,5 @@
int
strcoll(const char *s1, const char *s2)
{
- while (*s1 && *s2 && *s1 == *s2)
- ++s1, ++s2;
- return *(unsigned char *) s1 - *(unsigned char *) s2;
+ return strcmp(s1, s2);
}
DIR diff --git a/src/libc/string/strncat.c b/src/libc/string/strncat.c
@@ -5,11 +5,10 @@
char *
strncat(char *restrict s1, const char *restrict s2, size_t n)
{
- char *ret = s1;
-
- while(*s1)
- ++s1;
+ char *ret;
+ for (ret = s1; *s1; ++s1)
+ ;
while (n-- > 0 && *s2)
*s1++ = *s2++;
*s1 = '\0';
DIR diff --git a/src/libc/string/strrchr.c b/src/libc/string/strrchr.c
@@ -5,10 +5,10 @@
char *
strrchr(const char *s, int c)
{
- const char *t = s;
+ const char *t;
- while (*t)
- ++t;
+ for (t = s; *t; ++t)
+ ;
while (t > s && *t != c)
--t;
DIR diff --git a/src/libc/string/strstr.c b/src/libc/string/strstr.c
@@ -8,7 +8,7 @@ strstr(const char *s1, const char *s2)
{
const char *p;
int c = *s2;
- int len;
+ size_t len;
if ((len = strlen(s2)) == 0)
return (char *) s1;