mirror of
https://github.com/ivoszbg/uniLoader.git
synced 2024-11-21 19:40:07 +00:00
lib: unic: Implement strcat
Also fix-up the strncpy func. Signed-off-by: Ivaylo Ivanov <ivo.ivanov.ivanov1@gmail.com>
This commit is contained in:
parent
784bfd609a
commit
be0ad76a97
@ -99,24 +99,21 @@ char *strcpy(char *s1, const char *s2)
|
||||
return rc;
|
||||
}
|
||||
|
||||
char *strncpy(char *s1, const char *s2, size_t n)
|
||||
|
||||
char *strncpy(char *d, char *s, long n)
|
||||
{
|
||||
char *rc = s1;
|
||||
int len = strlen(s);
|
||||
if (len > n)
|
||||
len = n;
|
||||
memcpy(d, s, len);
|
||||
memset(d + len, 0, n - len);
|
||||
return d;
|
||||
}
|
||||
|
||||
while (n && (*s1++ = *s2++)) {
|
||||
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
|
||||
to check it again for >0 in the next loop below, so we must not risk
|
||||
underflow.
|
||||
*/
|
||||
--n;
|
||||
}
|
||||
|
||||
/* Checking against 1 as we missed the last --n in the loop above. */
|
||||
while (n-- > 1) {
|
||||
*s1++ = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
char *strcat(char *d, char *s)
|
||||
{
|
||||
strcpy(d + strlen(d), s);
|
||||
return d;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
|
@ -16,7 +16,8 @@
|
||||
int memcmp (const void *s1, const void *s2, size_t n);
|
||||
void *memchr (const void *s, int c, size_t n);
|
||||
char *strcpy (char *s1, const char *s2);
|
||||
char *strncpy (char *s1, const char *s2, size_t n);
|
||||
char *strncpy (char *d, char *s, long n);
|
||||
char *strcat (char *d, char *s);
|
||||
int strcmp (const char *s1, const char *s2);
|
||||
int strncmp (const char *s1, const char *s2, size_t n);
|
||||
size_t strlen (const char *s);
|
||||
|
Loading…
Reference in New Issue
Block a user