libc: Implement stpcpy

This function is unsafe so it is marked as deprecated, but if programs need it they can use it.
This commit is contained in:
apio 2022-11-12 13:20:28 +01:00
parent 16e6fba2d0
commit 3f867b936e
2 changed files with 12 additions and 0 deletions

View File

@ -91,6 +91,11 @@ extern "C"
__lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest, __lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest,
const char* src); const char* src);
#ifdef _GNU_SOURCE
/* Copies the string src into dest, returning a pointer to the end of dest. */
__lc_is_deprecated char* stpcpy(char* dest, const char* src);
#endif
char* strtok(char* str, const char* delim); // Not implemented. char* strtok(char* str, const char* delim); // Not implemented.
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -111,6 +111,13 @@ extern "C"
return len; return len;
} }
char* stpcpy(char* dest, const char* src)
{
size_t len = strlen(src);
size_t rc = strlcpy(dest, src, len + 1);
return dest + rc;
}
int strcmp(const char* a, const char* b) int strcmp(const char* a, const char* b)
{ {
while (*a && (*a == *b)) while (*a && (*a == *b))