1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 13:17:35 +00:00

LibC: Implement stpcpy

For better code clarity, also reformatted how strcpy increments
pointers.
This commit is contained in:
Dominika Liberda 2023-06-11 06:00:11 +02:00 committed by Linus Groh
parent 8a43f5a64a
commit 75307803a2
2 changed files with 15 additions and 2 deletions

View file

@ -187,11 +187,23 @@ void* memmem(void const* haystack, size_t haystack_length, void const* needle, s
char* strcpy(char* dest, char const* src) char* strcpy(char* dest, char const* src)
{ {
char* original_dest = dest; char* original_dest = dest;
while ((*dest++ = *src++) != '\0') while ((*dest = *src) != '\0') {
; dest++;
src++;
}
return original_dest; return original_dest;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/stpcpy.html
char* stpcpy(char* dest, char const* src)
{
while ((*dest = *src) != '\0') {
dest++;
src++;
}
return dest;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strncpy.html // https://pubs.opengroup.org/onlinepubs/9699919799/functions/strncpy.html
char* strncpy(char* dest, char const* src, size_t n) char* strncpy(char* dest, char const* src, size_t n)
{ {

View file

@ -37,6 +37,7 @@ __attribute__((malloc)) char* strdup(char const*);
__attribute__((malloc)) char* strndup(char const*, size_t); __attribute__((malloc)) char* strndup(char const*, size_t);
char* strcpy(char* dest, char const* src); char* strcpy(char* dest, char const* src);
char* stpcpy(char* dest, char const* src);
char* strncpy(char* dest, char const* src, size_t); char* strncpy(char* dest, char const* src, size_t);
__attribute__((warn_unused_result)) size_t strlcpy(char* dest, char const* src, size_t); __attribute__((warn_unused_result)) size_t strlcpy(char* dest, char const* src, size_t);