summaryrefslogtreecommitdiff
path: root/src/fl_string_functions.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-03-02 23:49:35 +0100
committerMatthias Melcher <github@matthiasm.com>2024-03-02 23:49:35 +0100
commitf1c9b198bba52d19a840efc7a77a9752d711ee57 (patch)
tree90ec58fa6e6ab849ae86ac39215588698feaa972 /src/fl_string_functions.cxx
parent4ccadff4b9120cba114da964fd0e79c762a6fd3d (diff)
Promote fl_strlcpy to <FL/fl_string_functions.h>
Diffstat (limited to 'src/fl_string_functions.cxx')
-rw-r--r--src/fl_string_functions.cxx32
1 files changed, 32 insertions, 0 deletions
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);
+}
+
+