tst-memstream.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Common definitions for open_memstream tests.
  2. Copyright (C) 2018-2019 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. <http://www.gnu.org/licenses/>. */
  15. #include <mcheck.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdarg.h>
  20. #include <errno.h>
  21. #include <support/check.h>
  22. #ifdef TEST_WCHAR
  23. # include <wchar.h>
  24. /* Straighforward implementation so tst-memstream3 could use check
  25. fwrite on open_memstream. */
  26. static size_t __attribute__ ((used))
  27. fwwrite (const void *ptr, size_t size, size_t nmemb, FILE *arq)
  28. {
  29. const wchar_t *wcs = (const wchar_t*) (ptr);
  30. for (size_t s = 0; s < size; s++)
  31. {
  32. for (size_t n = 0; n < nmemb; n++)
  33. if (fputwc (wcs[n], arq) == WEOF)
  34. return n;
  35. }
  36. return size * nmemb;
  37. }
  38. # define CHAR_T wchar_t
  39. # define W(o) L##o
  40. # define OPEN_MEMSTREAM open_wmemstream
  41. # define PRINTF wprintf
  42. # define FWRITE fwwrite
  43. # define FPUTC fputwc
  44. # define FPUTS fputws
  45. # define STRCMP wcscmp
  46. # define STRLEN wcslen
  47. #else
  48. # define CHAR_T char
  49. # define W(o) o
  50. # define OPEN_MEMSTREAM open_memstream
  51. # define PRINTF printf
  52. # define FWRITE fwrite
  53. # define FPUTC fputc
  54. # define FPUTS fputs
  55. # define STRCMP strcmp
  56. # define STRLEN strlen
  57. #endif
  58. #define S(s) S1 (s)
  59. #define S1(s) #s