Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. char *curl_mvaprintf(const char *format, va_list ap_save)
  2. {
  3. int retcode;
  4. struct asprintf info;
  5.  
  6. info.buffer = NULL;
  7. info.len = 0;
  8. info.alloc = 0;
  9. info.fail = 0;
  10.  
  11. retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
  12. if((-1 == retcode) || info.fail) {
  13. if(info.alloc)
  14. free(info.buffer);
  15. return NULL;
  16. }
  17.  
  18. if(info.alloc) {
  19. info.buffer[info.len] = 0; /* we terminate this with a zero byte */
  20. return info.buffer;
  21. }
  22. return strdup("");
  23. }
  24.  
  25. CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...)
  26. {
  27. char *s;
  28. va_list ap;
  29. va_start(ap, fmt);
  30. s = vaprintf(fmt, ap); /* this allocs a new string to append */
  31. va_end(ap);
  32.  
  33. if(s) {
  34. CURLcode result = Curl_add_buffer(in, s, strlen(s));
  35. free(s);
  36. return result;
  37. }
  38. /* If we failed, we cleanup the whole buffer and return error */
  39. free(in->buffer);
  40. free(in);
  41. return CURLE_OUT_OF_MEMORY;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement