From 2a01050a0cf0826f25240e2cb407535394ee360f Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 9 Feb 2014 12:38:50 -0500 Subject: Add capability to read table flag fields from Lua API --- src/util/string.cpp | 13 +++++++++++++ src/util/string.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/util') diff --git a/src/util/string.cpp b/src/util/string.cpp index afe40610c..a3888c9ce 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -163,6 +163,19 @@ std::string writeFlagString(u32 flags, FlagDesc *flagdesc, u32 flagmask) return result; } +size_t mystrlcpy(char *dst, const char *src, size_t size) +{ + size_t srclen = strlen(src) + 1; + size_t copylen = MYMIN(srclen, size); + + if (copylen > 0) { + memcpy(dst, src, copylen); + dst[copylen - 1] = '\0'; + } + + return srclen; +} + char *mystrtok_r(char *s, const char *sep, char **lasts) { char *t; diff --git a/src/util/string.h b/src/util/string.h index d6a9926ab..9bb89f14a 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -321,6 +321,7 @@ std::string urlencode(std::string str); std::string urldecode(std::string str); u32 readFlagString(std::string str, FlagDesc *flagdesc, u32 *flagmask); std::string writeFlagString(u32 flags, FlagDesc *flagdesc, u32 flagmask); +size_t mystrlcpy(char *dst, const char *src, size_t size); char *mystrtok_r(char *s, const char *sep, char **lasts); u64 read_seed(const char *str); -- cgit v1.2.3