This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "inttostr.h"
22 #include "intprops.h"
23 #include <inttypes.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "macros.h"
29
30 #define STREQ(a, b) (strcmp (a, b) == 0)
31 #define IS_TIGHT(T) (_GL_SIGNED_TYPE_OR_EXPR (T) == TYPE_SIGNED (T))
32 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
33
34
35
36
37
38
39
40 #define CK(T, Fn) \
41 do \
42 { \
43 char ref[100]; \
44 char *buf = malloc (INT_BUFSIZE_BOUND (T)); \
45 char const *p; \
46 ASSERT (buf); \
47 *buf = '\0'; \
48 ASSERT \
49 ((TYPE_SIGNED (T) \
50 ? snprintf (ref, sizeof ref, "%jd", (intmax_t) TYPE_MINIMUM (T)) \
51 : snprintf (ref, sizeof ref, "%ju", (uintmax_t) TYPE_MINIMUM (T))) \
52 < sizeof ref); \
53 ASSERT (STREQ ((p = Fn (TYPE_MINIMUM (T), buf)), ref)); \
54 \
55 ASSERT (! TYPE_SIGNED (T) || (p == buf && *p == '-')); \
56 ASSERT \
57 ((TYPE_SIGNED (T) \
58 ? snprintf (ref, sizeof ref, "%jd", (intmax_t) TYPE_MAXIMUM (T)) \
59 : snprintf (ref, sizeof ref, "%ju", (uintmax_t) TYPE_MAXIMUM (T))) \
60 < sizeof ref); \
61 ASSERT (STREQ ((p = Fn (TYPE_MAXIMUM (T), buf)), ref)); \
62 \
63 ASSERT (! IS_TIGHT (T) || TYPE_SIGNED (T) \
64 || (p == buf && ISDIGIT (*p))); \
65 free (buf); \
66 } \
67 while (0)
68
69 int
70 main (void)
71 {
72 size_t b_size = 2;
73 char *b = malloc (b_size);
74 ASSERT (b);
75
76
77
78
79 if (snprintf (b, b_size, "%ju", (uintmax_t) 3) == 1
80 && b[0] == '3' && b[1] == '\0')
81 {
82 CK (int, inttostr);
83 CK (unsigned int, uinttostr);
84 CK (off_t, offtostr);
85 CK (uintmax_t, umaxtostr);
86 CK (intmax_t, imaxtostr);
87 free (b);
88 return 0;
89 }
90
91
92 free (b);
93 return 77;
94 }