Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. int alloc_snprintf(char** out, const char* template, ...)
  2. {
  3. va_list list;
  4. va_start(list, template);
  5.  
  6. int len = vsnprintf(NULL, 0, template, list);
  7. va_end(list);
  8. char* new_string = malloc((size_t)len + 1);
  9. assert(new_string != NULL);
  10.  
  11. *out = new_string;
  12. va_start(list, template);
  13. len = vsnprintf(new_string, (size_t)len+1, template, list);
  14. va_end(list);
  15.  
  16. return len;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement