1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 10:18:15 +09:00

LibC: Implement strlcpy

This commit is contained in:
Ben Wiederhake 2020-08-23 12:09:42 +02:00 committed by Andreas Kling
parent 3fc2c4866f
commit 41b70ae8ba
Notes: sideshowbarker 2024-07-19 03:14:36 +09:00

View file

@ -216,10 +216,15 @@ char* strncpy(char* dest, const char* src, size_t n)
size_t strlcpy(char* dest, const char* src, size_t n)
{
(void)dest;
(void)src;
(void)n;
return 42; // TODO
size_t i;
// Would like to test i < n - 1 here, but n might be 0.
for (i = 0; i + 1 < n && src[i] != '\0'; ++i)
dest[i] = src[i];
if (n)
dest[i] = '\0';
for (; src[i] != '\0'; ++i)
; // Determine the length of src, don't copy.
return i;
}
char* strchr(const char* str, int c)