1 | #include <stdio.h> |
2 | #include <wchar.h> |
3 | |
4 | |
5 | static int fd; |
6 | |
7 | static void prepare (void); |
8 | #define PREPARE(argc, argv) prepare () |
9 | |
10 | |
11 | #define TEST_FUNCTION do_test () |
12 | static int do_test (void); |
13 | #include "../test-skeleton.c" |
14 | |
15 | |
16 | static void |
17 | prepare (void) |
18 | { |
19 | fd = create_temp_file (base: "wrewind2." , NULL); |
20 | if (fd == -1) |
21 | exit (3); |
22 | } |
23 | |
24 | |
25 | static int |
26 | do_test (void) |
27 | { |
28 | wchar_t dummy[10]; |
29 | int ret = 0; |
30 | FILE *fp; |
31 | int result = 0; |
32 | |
33 | fp = fdopen (fd, "w+" ); |
34 | if (fp == NULL) |
35 | { |
36 | puts (s: "fopen(" "testfile" ", " "w+" ") returned NULL." ); |
37 | return 1; |
38 | } |
39 | else |
40 | { |
41 | fwprintf (stream: fp, format: L"abcd" ); |
42 | printf (format: "current pos = %ld\n" , ftell (stream: fp)); |
43 | if (ftell (stream: fp) != 4) |
44 | result = 1; |
45 | |
46 | rewind (fp); |
47 | ret = fwscanf (stream: fp, format: L"%c" , dummy); |
48 | if (ret != 1) |
49 | { |
50 | printf (format: "fwscanf returned %d, expected 1\n" , ret); |
51 | result = 1; |
52 | } |
53 | |
54 | printf (format: "current pos = %ld\n" , ftell (stream: fp)); |
55 | if (ftell (stream: fp) != 1) |
56 | result = 1; |
57 | |
58 | rewind (fp); |
59 | printf (format: "current pos = %ld\n" , ftell (stream: fp)); |
60 | if (ftell (stream: fp) != 0) |
61 | result = 1; |
62 | |
63 | fclose (fp); |
64 | } |
65 | |
66 | return result; |
67 | } |
68 | |