Import strcat and strncat from FreeBSD
This commit is contained in:
parent
359d55f53c
commit
6cc254dd24
@ -15,5 +15,8 @@ size_t strlen(const char *str);
|
||||
int strncmp(const char *s1, const char *s2, size_t len);
|
||||
char *strncpy(char *to, const char *from, size_t len);
|
||||
|
||||
char *strcat(char *s, const char *append);
|
||||
char *strncat(char *s, const char *append, size_t count);
|
||||
|
||||
#endif /* __STRING_H__ */
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
* Copyright (c) 2013-2014 Stanford University
|
||||
* Copyright (c) 2006-2008 Ali Mashtizadeh
|
||||
* All rights reserved.
|
||||
*
|
||||
* XXX: add BSD copyright
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
@ -43,6 +45,41 @@ strncpy(char *to, const char *from, size_t length)
|
||||
return save;
|
||||
}
|
||||
|
||||
char *
|
||||
strcat(char *s, const char *append)
|
||||
{
|
||||
char *save = s;
|
||||
|
||||
for (; *s; ++s);
|
||||
while ((*s++ = *append++));
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
strncat(char *dst, const char *src, size_t n)
|
||||
{
|
||||
if (n != 0) {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
while (*d != 0)
|
||||
d++;
|
||||
|
||||
do {
|
||||
if ((*d = *s++) == 0)
|
||||
break;
|
||||
|
||||
d++;
|
||||
} while (--n != 0);
|
||||
|
||||
*d = 0;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user