casprintf.c 673 B

1234567891011121314151617181920212223242526272829303132333435
  1. #define _GNU_SOURCE
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "xmlrpc_config.h" /* For HAVE_ASPRINTF */
  6. #include "casprintf.h"
  7. void GNU_PRINTF_ATTR(2,3)
  8. casprintf(const char ** const retvalP, const char * const fmt, ...) {
  9. char *retval;
  10. va_list varargs; /* mysterious structure used by variable arg facility */
  11. va_start(varargs, fmt); /* start up the mysterious variable arg facility */
  12. #if HAVE_ASPRINTF
  13. vasprintf(&retval, fmt, varargs);
  14. #else
  15. retval = malloc(8192);
  16. vsnprintf(retval, 8192, fmt, varargs);
  17. #endif
  18. *retvalP = retval;
  19. }
  20. void
  21. strfree(const char * const string) {
  22. free((void *)string);
  23. }