diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 19 |
2 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index d9d030432d3..22b41d0055b 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -73,6 +73,12 @@ char *BLI_strncpy(char *dst, const char *src, int maxncpy); */ int BLI_snprintf(char *buffer, size_t count, const char *format, ...); + /* + * Print formatted string into a newly mallocN'd string + * and return it. + */ +char *BLI_sprintfN(const char *format, ...); + /** * Compare two strings * diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index e0522e60dd0..8485a0c975b 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -40,6 +40,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_dynstr.h" #include "BLI_string.h" char *BLI_strdupn(const char *str, int len) { @@ -81,6 +82,24 @@ int BLI_snprintf(char *buffer, size_t count, const char *format, ...) return n; } +char *BLI_sprintfN(const char *format, ...) +{ + DynStr *ds; + va_list arg; + char *n; + + va_start(arg, format); + + ds= BLI_dynstr_new(); + BLI_dynstr_vappendf(ds, format, arg); + n= BLI_dynstr_get_cstring(ds); + BLI_dynstr_free(ds); + + va_end(arg); + + return n; +} + int BLI_streq(char *a, char *b) { return (strcmp(a, b)==0); } |