1 #include <assert.h>
2 #include <errno.h>
3 #include <stdio.h>
4
5 #ifndef CHAR
6 # define CHAR char
7 # define L(str) str
8 # define FPUTS fputs
9 # define FSCANF fscanf
10 #endif
11
12
13 static int
14 do_test (void)
15 {
16 FILE *fp = tmpfile ();
17 if (fp == NULL)
18 {
19 puts ("cannot open file");
20 return 1;
21 }
22
23 FPUTS (L("7-11"), fp);
24 rewind (fp);
25
26 printf("setting errno to EINTR\n");
27 errno = EINTR;
28
29 printf("checking sscanf\n");
30
31 int i, j, n;
32 int result = 0;
33
34 i = j = n = 0;
35 if (FSCANF (fp, L(" %i - %i %n"), &i, &j, &n) < 2)
36 {
37 printf ("FSCANF couldn't read all parameters %d\n", errno);
38 result = 1;
39 }
40
41 printf ("found %i-%i (length=%i)\n", i, j, n);
42
43 if (i != 7)
44 {
45 printf ("i is %d, expected 7\n", i);
46 result = 1;
47 }
48 if (j != 11)
49 {
50 printf ("j is %d, expected 11\n", j);
51 result = 1;
52 }
53 if (n != 4)
54 {
55 printf ("n is %d, expected 4\n", j);
56 result = 1;
57 }
58
59 return result;
60 }
61
62 #define TEST_FUNCTION do_test ()
63 #include "../test-skeleton.c"