Created
January 24, 2017 23:02
-
-
Save Cactus64k/0d3f9befd76e62fcde66e5bb3f97b7d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int alloc_snprintf(char** out, const char* template, ...) | |
{ | |
va_list list; | |
va_start(list, template); | |
int len = vsnprintf(NULL, 0, template, list); | |
va_end(list); | |
char* new_string = malloc((size_t)len + 1); | |
assert(new_string != NULL); | |
*out = new_string; | |
va_start(list, template); | |
len = vsnprintf(new_string, (size_t)len+1, template, list); | |
va_end(list); | |
return len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment