]> git.ipfire.org Git - thirdparty/glibc.git/blob - stdio-common/tstdiomisc.c
update from main archive 970121
[thirdparty/glibc.git] / stdio-common / tstdiomisc.c
1 #include <stdio.h>
2
3 int
4 t1 (void)
5 {
6 int n = -1;
7 sscanf ("abc ", "abc %n", &n);
8 printf ("t1: count=%d\n", n);
9
10 return n != 5;
11 }
12
13 int
14 t2 (void)
15 {
16 int result = 0;
17 int n;
18 long N;
19 int retval;
20 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
21 VAR = -1; \
22 retval = sscanf (INPUT, FORMAT, &VAR); \
23 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
24 INPUT, FORMAT, retval, VAR); \
25 result |= retval != EXP_RES || VAR != EXP_VAL
26
27 SCAN ("12345", "%ld", N, 1, 12345);
28 SCAN ("12345", "%llllld", N, 0, -1);
29 SCAN ("12345", "%LLLLLd", N, 0, -1);
30 SCAN ("test ", "%*s%n", n, 0, 4);
31 SCAN ("test ", "%2*s%n", n, 0, -1);
32 SCAN ("12 ", "%l2d", n, 0, -1);
33 SCAN ("12 ", "%2ld", N, 1, 12);
34
35 return result;
36 }
37
38 int
39 main (int argc, char *argv[])
40 {
41 int result = 0;
42
43 result |= t1 ();
44 result |= t2 ();
45
46 result |= fflush (stdout) == EOF;
47
48 return result;
49 }