libs/libc/string: fix various style issues in code

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2023-06-10 20:50:31 +03:00 committed by Xiang Xiao
parent 2a38c38b03
commit 187def2611
22 changed files with 36 additions and 23 deletions

View File

@ -37,8 +37,8 @@
no_builtin("memcmp")
int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
{
unsigned char *p1 = (unsigned char *)s1;
unsigned char *p2 = (unsigned char *)s2;
FAR unsigned char *p1 = (FAR unsigned char *)s1;
FAR unsigned char *p2 = (FAR unsigned char *)s2;
while (n-- > 0)
{

View File

@ -43,7 +43,11 @@ FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n)
{
FAR unsigned char *pout = (FAR unsigned char *)dest;
FAR unsigned char *pin = (FAR unsigned char *)src;
while (n-- > 0) *pout++ = *pin++;
while (n-- > 0)
{
*pout++ = *pin++;
}
return dest;
}
#endif

View File

@ -42,6 +42,7 @@
*
****************************************************************************/
#undef memmem /* See mm/README.txt */
FAR void *memmem(FAR const void *haystack, size_t haystacklen,
FAR const void *needle, size_t needlelen)
{

View File

@ -30,10 +30,6 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mempcpy
****************************************************************************/
/****************************************************************************
* Name: mempcpy
*
@ -55,6 +51,7 @@
*
****************************************************************************/
#undef mempcpy /* See mm/README.txt */
FAR void *mempcpy(FAR void *dest, FAR const void *src, size_t n)
{
return (FAR char *)memcpy(dest, src, n) + n;

View File

@ -44,6 +44,7 @@
*
****************************************************************************/
#undef memrchr /* See mm/README.txt */
FAR void *memrchr(FAR const void *s, int c, size_t n)
{
FAR const unsigned char *p = (FAR const unsigned char *)s + n;

View File

@ -44,9 +44,9 @@
*
****************************************************************************/
void lib_skipspace(const char **pptr)
void lib_skipspace(FAR const char **pptr)
{
const char *ptr = *pptr;
FAR const char *ptr = *pptr;
while (isspace(*ptr)) ptr++;
*pptr = ptr;
}

View File

@ -44,6 +44,7 @@
****************************************************************************/
#ifndef CONFIG_ARCH_STPCPY
#undef stpcpy /* See mm/README.txt */
FAR char *stpcpy(FAR char *dest, FAR const char *src)
{
while ((*dest++ = *src++) != '\0');

View File

@ -54,6 +54,7 @@
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STPNCPY
#undef stpncpy /* See mm/README.txt */
FAR char *stpncpy(FAR char *dest, FAR const char *src, size_t n)
{
FAR char *end = dest + n; /* End of dest buffer + 1 byte */

View File

@ -32,11 +32,12 @@
* Private Functions
****************************************************************************/
#undef strcasechr /* See mm/README.txt */
static FAR char *strcasechr(FAR const char *s, int uc)
{
register char ch;
for (; *s; s++)
for (; *s != '\0'; s++)
{
ch = *s;
if (toupper(ch) == uc)

View File

@ -57,7 +57,7 @@ FAR char *strchr(FAR const char *s, int c)
return (FAR char *)s;
}
if (*s == 0)
if (*s == '\0')
{
break;
}

View File

@ -47,11 +47,12 @@
****************************************************************************/
#if !defined(CONFIG_LIBC_ARCH_STRCHRNUL) && defined(LIBC_BUILD_STRING)
#undef strchrnul /* See mm/README.txt */
FAR char *strchrnul(FAR const char *s, int c)
{
if (s)
{
while (*s && *s != c)
while (*s != '\0' && *s != c)
{
s++;
}

View File

@ -48,7 +48,7 @@
#undef strcpy /* See mm/README.txt */
FAR char *strcpy(FAR char *dest, FAR const char *src)
{
char *tmp = dest;
FAR char *tmp = dest;
while ((*dest++ = *src++) != '\0');
return tmp;
}

View File

@ -47,6 +47,7 @@
****************************************************************************/
#if !defined(CONFIG_LIBC_ARCH_STRLCAT) && defined(LIBC_BUILD_STRING)
#undef strlcat /* See mm/README.txt */
size_t strlcat(FAR char *dst, FAR const char *src, size_t dsize)
{
FAR const char *odst = dst;

View File

@ -46,6 +46,7 @@
****************************************************************************/
#if !defined(CONFIG_LIBC_ARCH_STRLCPY) && defined(LIBC_BUILD_STRING)
#undef strlcpy /* See mm/README.txt */
size_t strlcpy(FAR char *dst, FAR const char *src, size_t dsize)
{
FAR const char *osrc = src;
@ -69,9 +70,9 @@ size_t strlcpy(FAR char *dst, FAR const char *src, size_t dsize)
*dst = '\0';
}
while (*src++);
while (*src++ != '\0');
}
return (src - osrc - 1);
return src - osrc - 1;
}
#endif

View File

@ -34,9 +34,9 @@
#if !defined(CONFIG_LIBC_ARCH_STRLEN) && defined(LIBC_BUILD_STRING)
#undef strlen /* See mm/README.txt */
size_t strlen(const char *s)
size_t strlen(FAR const char *s)
{
const char *sc;
FAR const char *sc;
for (sc = s; *sc != '\0'; ++sc);
return sc - s;
}

View File

@ -38,7 +38,7 @@ FAR char *strncat(FAR char *dest, FAR const char *src, size_t n)
{
FAR char *ret = dest;
dest += strlen(dest);
dest += strlen(dest);
for (; n > 0 && *src != '\0' ; n--)
{
*dest++ = *src++;

View File

@ -33,9 +33,10 @@
****************************************************************************/
#if !defined(CONFIG_LIBC_ARCH_STRNLEN) && defined(LIBC_BUILD_STRING)
size_t strnlen(const char *s, size_t maxlen)
#undef strnlen /* See mm/README.txt */
size_t strnlen(FAR const char *s, size_t maxlen)
{
const char *sc;
FAR const char *sc;
for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc);
return sc - s;
}

View File

@ -46,6 +46,7 @@
*
****************************************************************************/
#undef strsep /* See mm/README.txt */
FAR char *strsep(FAR char **strp, FAR const char *delim)
{
FAR char *sbegin = *strp;

View File

@ -51,6 +51,7 @@
* string haystack. Returns NULL if needle was not found.
*/
#undef strstr /* See mm/README.txt */
FAR char *strstr(FAR const char *haystack, FAR const char *needle)
{
FAR const unsigned char *needle_cmp_end;

View File

@ -28,7 +28,7 @@
* Private Data
****************************************************************************/
static char *g_saveptr = NULL;
static FAR char *g_saveptr = NULL;
/****************************************************************************
* Public Functions
@ -67,7 +67,7 @@ static char *g_saveptr = NULL;
****************************************************************************/
#undef strtok /* See mm/README.txt */
char *strtok(char *str, const char *delim)
FAR char *strtok(FAR char *str, FAR const char *delim)
{
return strtok_r(str, delim, &g_saveptr);
}

View File

@ -75,6 +75,7 @@
*
****************************************************************************/
#undef strtok_r /* See mm/README.txt */
FAR char *strtok_r(FAR char *str, FAR const char *delim, FAR char **saveptr)
{
FAR char *pbegin;

View File

@ -69,7 +69,7 @@ size_t strxfrm(FAR char *s1, FAR const char *s2, size_t n)
return res;
}
}
while (*s2)
while (*s2 != '\0')
{
++s2;
++res;