diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_dynstr.c | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 6 |
3 files changed, 8 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index c722ffb1693..39123a438df 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -128,6 +128,7 @@ char *BLI_strcasestr(const char *s, const char *find); int BLI_strcasecmp(const char *s1, const char *s2); int BLI_strncasecmp(const char *s1, const char *s2, int n); int BLI_natstrcmp(const char *s1, const char *s2); +size_t BLI_strnlen(const char *str, size_t maxlen); void BLI_timestr(double _time, char *str); /* time var is global */ diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 4754d3bd8c3..5b61a86305b 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -39,9 +39,6 @@ #ifndef vsnprintf #define vsnprintf _vsnprintf #endif -#ifndef strnlen -#define strnlen _strnlen -#endif #endif /***/ @@ -86,7 +83,7 @@ void BLI_dynstr_append(DynStr *ds, const char *cstr) { void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) { DynStrElem *dse= malloc(sizeof(*dse)); - int cstrlen= strnlen(cstr, len); + int cstrlen= BLI_strnlen(cstr, len); dse->str= malloc(cstrlen+1); memcpy(dse->str, cstr, cstrlen); diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index bc9614667a7..c344d8c0711 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -342,3 +342,9 @@ void BLI_timestr(double _time, char *str) str[11]=0; } +/* determine the length of a fixed-size string */ +size_t BLI_strnlen(const char *str, size_t maxlen) +{ + const char *end = memchr(str, '\0', maxlen); + return end ? (size_t) (end - str) : maxlen; +} |