asprintf.h 611 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef __ASPRINTF_H
  2. #define __ASPRINTF_H
  3. #ifdef HAVE_CONFIG_H
  4. #include <config.h>
  5. #endif
  6. #ifndef HAVE_VASPRINTF
  7. static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
  8. {
  9. int res;
  10. char buf[16];
  11. res = vsnprintf(buf, 16, TEMPLATE, AP);
  12. if (res > 0) {
  13. *PTR = (char*)malloc(res+1);
  14. res = vsnprintf(*PTR, res+1, TEMPLATE, AP);
  15. }
  16. return res;
  17. }
  18. #endif
  19. #ifndef HAVE_ASPRINTF
  20. static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
  21. {
  22. int res;
  23. va_list AP;
  24. va_start(AP, TEMPLATE);
  25. res = vasprintf(PTR, TEMPLATE, AP);
  26. va_end(AP);
  27. return res;
  28. }
  29. #endif
  30. #endif /* ASPRINTF_H */