mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-29 13:03:38 +01:00
string: split strcat and strncat (DONE)
This commit is contained in:
parent
5d345b8da2
commit
3792bbd9d1
3 changed files with 13 additions and 33 deletions
|
@ -142,6 +142,7 @@ set(SOURCES
|
||||||
src/libc/string/strcpy.c
|
src/libc/string/strcpy.c
|
||||||
src/libc/string/strdup.c
|
src/libc/string/strdup.c
|
||||||
src/libc/string/strlen.c
|
src/libc/string/strlen.c
|
||||||
|
src/libc/string/strncat.c
|
||||||
src/libc/string/strncmp.c
|
src/libc/string/strncmp.c
|
||||||
src/libc/string/strncpy.c
|
src/libc/string/strncpy.c
|
||||||
src/libc/string/strnlen.c
|
src/libc/string/strnlen.c
|
||||||
|
|
|
@ -1,16 +1,5 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
|
||||||
** The strcat() function appends the src string to the dest string,
|
|
||||||
** overwriting the terminating null byte ('\0') at the end of dest, and then
|
|
||||||
** adds a terminating null byte. The strings may not overlap, and the dest
|
|
||||||
** string must have enough space for the result. If dest is not large enough,
|
|
||||||
** program behavior is unpredictable; buffer overruns are a favorite avenue for
|
|
||||||
** attacking secure programs.
|
|
||||||
**
|
|
||||||
** TODO: use the DMA !
|
|
||||||
** TODO: look at the DSP ?
|
|
||||||
*/
|
|
||||||
char *strcat(char *dest, char const *src)
|
char *strcat(char *dest, char const *src)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -26,25 +15,3 @@ char *strcat(char *dest, char const *src)
|
||||||
dest[i + start] = '\0';
|
dest[i + start] = '\0';
|
||||||
return (dest);
|
return (dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
** The strncat() function is similar, except that:
|
|
||||||
** * it will use at most n bytes from src; and
|
|
||||||
** * src does not need to be null-terminated if it contains n or more bytes.
|
|
||||||
**
|
|
||||||
** As with strcat(), the resulting string in dest is always null-terminated.
|
|
||||||
**
|
|
||||||
** If src contains n or more bytes, strncat() writes n+1 bytes to dest (n from
|
|
||||||
** src plus the terminating null byte). Therefore, the size of dest must be at
|
|
||||||
** least strlen(dest)+n+1.
|
|
||||||
*/
|
|
||||||
char *strncat(char *dest, const char *src, size_t n)
|
|
||||||
{
|
|
||||||
size_t dest_len = strlen(dest);
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < n && src[i] != '\0'; i++)
|
|
||||||
dest[dest_len + i] = src[i];
|
|
||||||
dest[dest_len + i] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
12
src/libc/string/strncat.c
Normal file
12
src/libc/string/strncat.c
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *strncat(char *dest, const char *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t dest_len = strlen(dest);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < n && src[i] != '\0'; i++)
|
||||||
|
dest[dest_len + i] = src[i];
|
||||||
|
dest[dest_len + i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
Loading…
Reference in a new issue