summaryrefslogtreecommitdiff
path: root/Libraries/LibC/string.cpp
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2020-08-23 12:09:42 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-24 00:45:03 +0200
commit41b70ae8baf5e172040d52aa30aa9fa8615993ee (patch)
tree77c0a3c5caafad2a25e6d95dad68fd25fdee88b1 /Libraries/LibC/string.cpp
parent3fc2c4866fcb798d874d5d98e067b347d24cfe1d (diff)
downloadserenity-41b70ae8baf5e172040d52aa30aa9fa8615993ee.zip
LibC: Implement strlcpy
Diffstat (limited to 'Libraries/LibC/string.cpp')
-rw-r--r--Libraries/LibC/string.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Libraries/LibC/string.cpp b/Libraries/LibC/string.cpp
index 3e1b7890d2..744f6fc470 100644
--- a/Libraries/LibC/string.cpp
+++ b/Libraries/LibC/string.cpp
@@ -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)