summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-03-25 19:36:31 +0100
committerBruno Haible <bruno@clisp.org>2023-03-25 19:49:21 +0100
commiteb8da36e0b3a667444707fb7d0182e54bb2130d0 (patch)
tree2456cce91815d62e13640cffa4e786fecdfb87d4 /tests
parentfdae921011d0233db99799edbf4a858596265392 (diff)
downloadgnulib-eb8da36e0b3a667444707fb7d0182e54bb2130d0.tar.gz
stdio: ISO C 23: Define _PRINTF_NAN_LEN_MAX.
* lib/stdio.in.h (_PRINTF_NAN_LEN_MAX): New macro. * m4/stdio_h.m4 (gl_STDIO_H): Invoke gl_MUSL_LIBC. * modules/stdio (Files): Add m4/musl.m4. * tests/test-stdio.c: Check that _PRINTF_NAN_LEN_MAX is defined. Include nan.h, macros.h. (main): Check the value of _PRINTF_NAN_LEN_MAX. * modules/stdio-tests (Files): Add tests/nan.h, tests/macros.h, m4/exponentd.m4. (configure.ac): Invoke gl_DOUBLE_EXPONENT_LOCATION.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-stdio.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test-stdio.c b/tests/test-stdio.c
index a3b0a3e2ba..9794f4d856 100644
--- a/tests/test-stdio.c
+++ b/tests/test-stdio.c
@@ -23,6 +23,9 @@
/* Check that the various SEEK_* macros are defined. */
int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
+/* Check that the _PRINTF_NAN_LEN_MAX macro is defined. */
+int pnlm[] = { _PRINTF_NAN_LEN_MAX };
+
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
static_assert (sizeof NULL == sizeof (void *));
@@ -34,8 +37,37 @@ size_t t3;
ssize_t t4;
va_list t5;
+#include <string.h>
+
+#include "nan.h"
+#include "macros.h"
+
int
main (void)
{
+#if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+ /* Check the value of _PRINTF_NAN_LEN_MAX. */
+ {
+ #define NWORDS \
+ ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ typedef union { double value; unsigned int word[NWORDS]; } memory_double;
+
+ double value1;
+ memory_double value2;
+ char buf[64];
+
+ value1 = NaNd();
+ sprintf (buf, "%g", value1);
+ ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+
+ value2.value = NaNd ();
+ #if DBL_EXPBIT0_BIT == 20
+ value2.word[DBL_EXPBIT0_WORD] ^= 0x54321;
+ #endif
+ sprintf (buf, "%g", value2.value);
+ ASSERT (strlen (buf) <= _PRINTF_NAN_LEN_MAX);
+ }
+#endif
+
return 0;
}