From 36e0a1e970201a86ad727725febe0e3326e9f8fb Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 12 Mar 2023 11:10:18 +0100 Subject: [PATCH] libc: Add definitions for strnlen, strndup and strlcpy to string.h --- libc/include/string.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libc/include/string.h b/libc/include/string.h index dc58e4d8..9f2055e3 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -26,6 +26,9 @@ extern "C" /* Return the length of a null-terminated string. */ size_t strlen(const char* str); + /* Return the length of a fixed-size null-terminated string. */ + size_t strnlen(const char* str, size_t max); + /* Compare two null-terminated strings. */ int strcmp(const char* a, const char* b); @@ -56,6 +59,12 @@ extern "C" /* Separate a string into several tokens. */ char* strtok(char* str, const char* delim); + /* Return a heap-allocated copy of a fixed-size string. */ + char* strndup(const char* str, size_t max); + + /* Copy up to max bytes of src into dest, adding a null terminator at the end. */ + size_t strlcpy(char* dest, const char* src, size_t max); + #ifdef __cplusplus } #endif