software/libbase: add strcat strncat
This commit is contained in:
parent
20b137fce9
commit
8fa0198089
|
@ -29,6 +29,8 @@ char *strcpy(char *dest, const char *src);
|
||||||
char *strncpy(char *dest, const char *src, size_t count);
|
char *strncpy(char *dest, const char *src, size_t count);
|
||||||
int strcmp(const char *cs, const char *ct);
|
int strcmp(const char *cs, const char *ct);
|
||||||
int strncmp(const char *cs, const char *ct, size_t count);
|
int strncmp(const char *cs, const char *ct, size_t count);
|
||||||
|
char *strcat(char *dest, const char *src);
|
||||||
|
char *strncat(char *dest, const char *src, size_t n);
|
||||||
size_t strlen(const char *s);
|
size_t strlen(const char *s);
|
||||||
size_t strnlen(const char *s, size_t count);
|
size_t strnlen(const char *s, size_t count);
|
||||||
size_t strspn(const char *s, const char *accept);
|
size_t strspn(const char *s, const char *accept);
|
||||||
|
|
|
@ -160,6 +160,48 @@ int strncmp(const char *cs, const char *ct, size_t count)
|
||||||
return __res;
|
return __res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strcat - Append one %NUL-terminated string to another
|
||||||
|
* @dest: The string to be appended to
|
||||||
|
* @src: The string to append to it
|
||||||
|
*/
|
||||||
|
char *strcat(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
char *tmp = dest;
|
||||||
|
|
||||||
|
while (*dest)
|
||||||
|
dest++;
|
||||||
|
while ((*dest++ = *src++) != '\0')
|
||||||
|
;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strncat - Append a length-limited, %NUL-terminated string to another
|
||||||
|
* @dest: The string to be appended to
|
||||||
|
* @src: The string to append to it
|
||||||
|
* @count: The maximum numbers of bytes to copy
|
||||||
|
*
|
||||||
|
* Note that in contrast to strncpy(), strncat() ensures the result is
|
||||||
|
* terminated.
|
||||||
|
*/
|
||||||
|
char *strncat(char *dest, const char *src, size_t count)
|
||||||
|
{
|
||||||
|
char *tmp = dest;
|
||||||
|
|
||||||
|
if (count) {
|
||||||
|
while (*dest)
|
||||||
|
dest++;
|
||||||
|
while ((*dest++ = *src++) != 0) {
|
||||||
|
if (--count == 0) {
|
||||||
|
*dest = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strlen - Find the length of a string
|
* strlen - Find the length of a string
|
||||||
* @s: The string to be sized
|
* @s: The string to be sized
|
||||||
|
|
Loading…
Reference in New Issue