From f1c9b198bba52d19a840efc7a77a9752d711ee57 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 2 Mar 2024 23:49:35 +0100 Subject: Promote fl_strlcpy to --- src/fl_string_functions.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/fl_string_functions.cxx') diff --git a/src/fl_string_functions.cxx b/src/fl_string_functions.cxx index 6b7fcead7..2e5e5d5d4 100644 --- a/src/fl_string_functions.cxx +++ b/src/fl_string_functions.cxx @@ -32,3 +32,35 @@ char *fl_strdup(const char *s) { return Fl::system_driver()->strdup(s); } + +/* + * 'fl_strlcpy()' - Safely copy two strings. + */ +size_t /* O - Length of string */ +fl_strlcpy(char *dst, /* O - Destination string */ + const char *src, /* I - Source string */ + size_t size) { /* I - Size of destination string buffer */ + size_t srclen; /* Length of source string */ + + + /* + * Figure out how much room is needed... + */ + + size --; + + srclen = strlen(src); + + /* + * Copy the appropriate amount... + */ + + if (srclen > size) srclen = size; + + memcpy(dst, src, srclen); + dst[srclen] = '\0'; + + return (srclen); +} + + -- cgit v1.2.3