A mail formatter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.4 KiB

  1. /*
  2. * asprintf - Incenp.org Notch Library: (v)asprintf replacement
  3. * Copyright (C) 2011 Damien Goutte-Gattat
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <errno.h>
  25. int
  26. vasprintf(char **strp, const char *fmt, va_list ap)
  27. {
  28. int n;
  29. va_list aq;
  30. if ( ! strp ) {
  31. errno = EINVAL;
  32. return -1;
  33. }
  34. n = vsnprintf(NULL, 0, fmt, ap) + 1;
  35. if ( ! (*strp = malloc(n)) )
  36. return -1;
  37. va_copy(ap, aq);
  38. n = vsnprintf(*strp, n, fmt, aq);
  39. va_end(aq);
  40. return n;
  41. }
  42. int
  43. asprintf(char **strp, const char *fmt, ...)
  44. {
  45. int n;
  46. va_list ap;
  47. va_start(ap, fmt);
  48. n = vasprintf(strp, fmt, ap);
  49. va_end(ap);
  50. return n;
  51. }