lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | |
| 3 | |
| 4 | |
| 5 | int |
| 6 | main (void) |
| 7 | { |
| 8 | int res = 0; |
| 9 | char buf[100]; |
| 10 | |
| 11 | #define TEST(nr, result, format, args...) \ |
| 12 | if (sprintf (buf, format, ## args) != result) \ |
| 13 | { \ |
| 14 | printf ("test %d failed (\"%s\", %d)\n", nr, buf, result); \ |
| 15 | res = 1; \ |
| 16 | } |
| 17 | |
| 18 | TEST (1, 2, "%d", -1); |
| 19 | TEST (2, 2, "% 2d", 1); |
| 20 | TEST (3, 3, "%#x", 1); |
| 21 | TEST (4, 2, "%+d", 1); |
| 22 | TEST (5, 2, "% d", 1); |
| 23 | TEST (6, 2, "%-d", -1); |
| 24 | TEST (7, 2, "%- 2d", 1); |
| 25 | TEST (8, 3, "%-#x", 1); |
| 26 | TEST (9, 2, "%-+d", 1); |
| 27 | TEST (10, 2, "%- d", 1); |
| 28 | |
| 29 | return res; |
| 30 | } |