Update.
[glibc.git] / stdio-common / tst-printfsz.c
blobfed829c012787c2a20e0c6e2eedf7442412ea35a
1 /* Based on code by Larry McVoy <lm@neteng.engr.sgi.com>. */
2 #include <printf.h>
3 #include <stdio.h>
5 #define V 12345678.12345678
8 int
9 main (int argc, char *argv[])
11 char buf[1024];
12 int result = 0;
14 /* Register the printf handlers. */
15 register_printf_function ('b', printf_size, printf_size_info);
16 register_printf_function ('B', printf_size, printf_size_info);
19 sprintf (buf, "%g %b %B %.0b %.0B %.1b %.1B %8.0b %08.0B",
20 V, 1025., V, V, V, V, V, V, V, V);
21 fputs (buf, stdout);
22 if (strcmp (buf, "\
23 1.23457e+07 1.001k 12.346M 12m 12M 11.8m 12.3M 12m 0000012M"))
25 result = 1;
26 fputs (" -> WRONG\n", stdout);
28 else
29 fputs (" -> OK\n", stdout);
31 sprintf (buf, "%b|%B|%-20.2b|%-10.0b|%-10.8b|%-10.2B|",
32 V, V, V, V, V, V, V, V, V, V, V);
33 fputs (buf, stdout);
34 if (strcmp (buf, "\
35 11.774m|12.346M|11.77m |12m |11.77375614m|12.35M |"))
37 result = 1;
38 fputs (" -> WRONG\n", stdout);
40 else
41 fputs (" -> OK\n", stdout);
43 sprintf (buf, "%#.0B %*.0b %10.*b %*.*B %10.2B",
44 V, 2, V, 2, V, 10, 2, V, V);
45 fputs (buf, stdout);
46 if (strcmp (buf, "12.M 12m 11.77m 12.35M 12.35M"))
48 result = 1;
49 fputs (" -> WRONG\n", stdout);
51 else
52 fputs (" -> OK\n", stdout);
54 sprintf (buf, "%6B %6.1B %b %B %b %B",
55 V, V, 1000.0, 1000.0, 1024.0, 1024.0);
56 fputs (buf, stdout);
57 if (strcmp (buf, "12.346M 12.3M 1000.000 1.000K 1.000k 1.024K"))
59 result = 1;
60 fputs (" -> WRONG\n", stdout);
62 else
63 fputs (" -> OK\n", stdout);
65 return result;