tst-wmemstream3.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Test for open_memstream implementation.
  2. Copyright (C) 2016-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <wchar.h>
  16. /* Straightforward implementation so tst-memstream3 could use check
  17. fwrite on open_memstream. */
  18. static size_t
  19. fwwrite (const void *ptr, size_t size, size_t nmemb, FILE *arq)
  20. {
  21. const wchar_t *wcs = (const wchar_t*) (ptr);
  22. for (size_t s = 0; s < size; s++)
  23. {
  24. for (size_t n = 0; n < nmemb; n++)
  25. if (fputwc (wcs[n], arq) == WEOF)
  26. return n;
  27. }
  28. return size * nmemb;
  29. }
  30. #define CHAR_T wchar_t
  31. #define W(o) L##o
  32. #define OPEN_MEMSTREAM open_wmemstream
  33. #define PRINTF wprintf
  34. #define FWRITE_FUNC fwwrite
  35. #define FPUTC fputwc
  36. #define STRCMP wcscmp
  37. #include "tst-memstream3.c"