[v3,0/7] Fix some libm static issues
[platform/upstream/glibc.git] / libio / tst-memstream.h
1 /* Common definitions for open_memstream tests.
2    Copyright (C) 2018-2024 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library 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 GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18
19 #include <mcheck.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include <errno.h>
25
26 #include <support/check.h>
27
28 #ifdef TEST_WCHAR
29 # include <wchar.h>
30
31 /* Straightforward implementation so tst-memstream3 could use check
32    fwrite on open_memstream.  */
33 static size_t __attribute__ ((used))
34 fwwrite (const void *ptr, size_t size, size_t nmemb, FILE *arq)
35 {
36   const wchar_t *wcs = (const wchar_t*) (ptr);
37   for (size_t s = 0; s < size; s++)
38     {
39       for (size_t n = 0; n < nmemb; n++)
40         if (fputwc (wcs[n], arq) == WEOF)
41           return n;
42     }
43   return size * nmemb;
44 }
45
46 # define CHAR_T wchar_t
47 # define W(o) L##o
48 # define OPEN_MEMSTREAM open_wmemstream
49 # define PRINTF wprintf
50 # define FWRITE fwwrite
51 # define FPUTC  fputwc
52 # define FPUTS  fputws
53 # define STRCMP wcscmp
54 # define STRLEN wcslen
55 #else
56 # define CHAR_T char
57 # define W(o) o
58 # define OPEN_MEMSTREAM open_memstream
59 # define PRINTF printf
60 # define FWRITE fwrite
61 # define FPUTC fputc
62 # define FPUTS  fputs
63 # define STRCMP strcmp
64 # define STRLEN strlen
65 #endif
66
67 #define S(s) S1 (s)
68 #define S1(s) #s