From dddd0e7b0317f02e1aad5d60d87844da8f6785e4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Feb 2019 16:11:28 +0100 Subject: Get nyancat nyanning in Serenity. I found a cute program that renders an animated nyancat in the terminal. This patch adds enough hackery to get it working correctly. :^) --- LibC/string.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'LibC/string.cpp') diff --git a/LibC/string.cpp b/LibC/string.cpp index 02d8d934ea..47ddf45e3f 100644 --- a/LibC/string.cpp +++ b/LibC/string.cpp @@ -5,6 +5,7 @@ #include #include #include +#include extern "C" { @@ -60,6 +61,15 @@ char* strdup(const char* str) return new_str; } +char* strndup(const char* str, size_t maxlen) +{ + size_t len = min(strlen(str), maxlen); + char* new_str = (char*)malloc(len + 1); + memcpy(new_str, str, len); + new_str[len] = 0; + return new_str; +} + int strcmp(const char* s1, const char* s2) { while (*s1 == *s2++) -- cgit v1.2.3