|
0
|
1 #include "printf.h"
|
|
|
2
|
|
|
3 #include <locale.h>
|
|
|
4 #include <stdlib.h> /* malloc */
|
|
|
5 #include <limits.h>
|
|
|
6 #include <stdint.h>
|
|
|
7 #include <limits.h>
|
|
|
8 #include <float.h>
|
|
|
9
|
|
|
10 int test_fprintf(void)
|
|
|
11 {
|
|
|
12 int n, n2;
|
|
|
13 FILE *f1, *f2;
|
|
|
14
|
|
|
15 f1 = tmpfile();
|
|
|
16 f2 = tmpfile();
|
|
|
17
|
|
|
18 n = my_fprintf(f1,
|
|
|
19 #include "test.h"
|
|
|
20 );
|
|
|
21 if (n < 0) {
|
|
|
22 fprintf(stderr, "my_fprintf: %s\n", my_strerror(n));
|
|
|
23 return -1;
|
|
|
24 }
|
|
|
25 n2 = fprintf(f2,
|
|
|
26 #include "test.h"
|
|
|
27 );
|
|
|
28 if (n2 < 0) {
|
|
|
29 perror("fprintf");
|
|
|
30 return -1;
|
|
|
31 }
|
|
|
32
|
|
|
33 fseek(f1, 0, SEEK_SET);
|
|
|
34 fseek(f2, 0, SEEK_SET);
|
|
|
35
|
|
|
36 if (n != n2) {
|
|
|
37 fclose(f1);
|
|
|
38 fclose(f2);
|
|
|
39 return -1;
|
|
|
40 }
|
|
|
41
|
|
|
42 for (;;) {
|
|
|
43 int c1, c2;
|
|
|
44
|
|
|
45 c1 = fgetc(f1);
|
|
|
46 c2 = fgetc(f2);
|
|
|
47
|
|
|
48 if (c1 != c2) {
|
|
|
49 fprintf(stderr, "Got different results!!\n");
|
|
|
50 fprintf(stderr, " fprintf @ %ld: %c", ftell(f1), c1);
|
|
|
51 fprintf(stderr, " my_fprintf @ %ld: %c", ftell(f2), c2);
|
|
|
52
|
|
|
53 fclose(f1);
|
|
|
54 fclose(f2);
|
|
|
55 return -1;
|
|
|
56 }
|
|
|
57
|
|
|
58 if (c1 == EOF)
|
|
|
59 break;
|
|
|
60 }
|
|
|
61
|
|
|
62 fclose(f1);
|
|
|
63 fclose(f2);
|
|
|
64
|
|
|
65 return 0;
|
|
|
66 } |