libs/libc/string: unify implementation across the functions
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
b9827f7ede
commit
8f7af29d74
@ -35,10 +35,11 @@
|
|||||||
#undef strcasecmp /* See mm/README.txt */
|
#undef strcasecmp /* See mm/README.txt */
|
||||||
int strcasecmp(FAR const char *cs, FAR const char *ct)
|
int strcasecmp(FAR const char *cs, FAR const char *ct)
|
||||||
{
|
{
|
||||||
int result;
|
register int result;
|
||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs)
|
if ((result = toupper(*cs) - toupper(*ct)) != 0 ||
|
||||||
|
*cs == '\0')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,12 @@ static FAR char *strcasechr(FAR const char *s, int uc)
|
|||||||
{
|
{
|
||||||
register char ch;
|
register char ch;
|
||||||
|
|
||||||
if (s)
|
for (; *s; s++)
|
||||||
{
|
{
|
||||||
for (; *s; s++)
|
ch = *s;
|
||||||
|
if (toupper(ch) == uc)
|
||||||
{
|
{
|
||||||
ch = *s;
|
return (FAR char *)s;
|
||||||
if (toupper(ch) == uc)
|
|
||||||
{
|
|
||||||
return (FAR char *)s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ int strcmp(FAR const char *cs, FAR const char *ct)
|
|||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 ||
|
if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 ||
|
||||||
!*cs++)
|
*cs++ == '\0')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,13 @@
|
|||||||
|
|
||||||
#ifndef CONFIG_ARCH_STRNCASECMP
|
#ifndef CONFIG_ARCH_STRNCASECMP
|
||||||
#undef strncasecmp /* See mm/README.txt */
|
#undef strncasecmp /* See mm/README.txt */
|
||||||
int strncasecmp(const char *cs, const char *ct, size_t nb)
|
int strncasecmp(FAR const char *cs, FAR const char *ct, size_t nb)
|
||||||
{
|
{
|
||||||
int result = 0;
|
register int result = 0;
|
||||||
for (; nb > 0; nb--)
|
for (; nb > 0; nb--)
|
||||||
{
|
{
|
||||||
if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs)
|
if ((result = toupper(*cs) - toupper(*ct)) != 0 ||
|
||||||
|
*cs == '\0')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
#ifndef CONFIG_ARCH_STRNCAT
|
#ifndef CONFIG_ARCH_STRNCAT
|
||||||
#undef strncat /* See mm/README.txt */
|
#undef strncat /* See mm/README.txt */
|
||||||
char *strncat(char *dest, const char *src, size_t n)
|
FAR char *strncat(FAR char *dest, FAR const char *src, size_t n)
|
||||||
{
|
{
|
||||||
char *ret = dest;
|
FAR char *ret = dest;
|
||||||
|
|
||||||
dest += strlen(dest);
|
dest += strlen(dest);
|
||||||
for (; n > 0 && *src != '\0' ; n--)
|
for (; n > 0 && *src != '\0' ; n--)
|
||||||
|
@ -32,13 +32,13 @@
|
|||||||
|
|
||||||
#ifndef CONFIG_ARCH_STRNCMP
|
#ifndef CONFIG_ARCH_STRNCMP
|
||||||
#undef strncmp /* See mm/README.txt */
|
#undef strncmp /* See mm/README.txt */
|
||||||
int strncmp(const char *cs, const char *ct, size_t nb)
|
int strncmp(FAR const char *cs, FAR const char *ct, size_t nb)
|
||||||
{
|
{
|
||||||
int result = 0;
|
register int result = 0;
|
||||||
for (; nb > 0; nb--)
|
for (; nb > 0; nb--)
|
||||||
{
|
{
|
||||||
if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 ||
|
if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 ||
|
||||||
!*cs++)
|
*cs++ == '\0')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user