dupwcscat.c 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Implementation function behind dupwcscat() in misc.h.
  3. *
  4. * This function is called with an arbitrary number of 'const wchar_t
  5. * *' parameters, of which the last one is a null pointer. The wrapper
  6. * macro puts on the null pointer itself, so normally callers don't
  7. * have to.
  8. */
  9. #include <stdarg.h>
  10. #include <wchar.h>
  11. #include "defs.h"
  12. #include "misc.h"
  13. wchar_t *dupwcscat_fn(const wchar_t *s1, ...)
  14. {
  15. int len;
  16. wchar_t *p, *q, *sn;
  17. va_list ap;
  18. len = wcslen(s1);
  19. va_start(ap, s1);
  20. while (1) {
  21. sn = va_arg(ap, wchar_t *);
  22. if (!sn)
  23. break;
  24. len += wcslen(sn);
  25. }
  26. va_end(ap);
  27. p = snewn(len + 1, wchar_t);
  28. wcscpy(p, s1);
  29. q = p + wcslen(p);
  30. va_start(ap, s1);
  31. while (1) {
  32. sn = va_arg(ap, wchar_t *);
  33. if (!sn)
  34. break;
  35. wcscpy(q, sn);
  36. q += wcslen(q);
  37. }
  38. va_end(ap);
  39. return p;
  40. }