]>
Commit | Line | Data |
---|---|---|
5d2e6976 AS |
1 | /* Test program for fsetpos on a wide character stream. */ |
2 | ||
3 | #include <assert.h> | |
4 | #include <stdio.h> | |
5 | #include <wchar.h> | |
6 | ||
7 | static void do_prepare (void); | |
8 | #define PREPARE(argc, argv) do_prepare () | |
9 | static int do_test (void); | |
10 | #define TEST_FUNCTION do_test () | |
11 | #include <test-skeleton.c> | |
12 | ||
13 | static const char pattern[] = "12345"; | |
14 | static char *temp_file; | |
15 | ||
16 | static void | |
17 | do_prepare (void) | |
18 | { | |
19 | int fd = create_temp_file ("bug-wsetpos.", &temp_file); | |
20 | if (fd == -1) | |
21 | { | |
22 | printf ("cannot create temporary file: %m\n"); | |
23 | exit (1); | |
24 | } | |
25 | write (fd, pattern, sizeof (pattern)); | |
26 | close (fd); | |
27 | } | |
28 | ||
29 | static int | |
30 | do_test (void) | |
31 | { | |
32 | FILE *fp = fopen (temp_file, "r"); | |
33 | fpos_t pos; | |
34 | wchar_t c; | |
35 | ||
36 | if (fp == NULL) | |
37 | { | |
38 | printf ("fdopen: %m\n"); | |
39 | return 1; | |
40 | } | |
41 | ||
42 | c = fgetwc (fp); assert (c == L'1'); | |
43 | c = fgetwc (fp); assert (c == L'2'); | |
44 | ||
45 | if (fgetpos (fp, &pos) == EOF) | |
46 | { | |
47 | printf ("fgetpos: %m\n"); | |
48 | return 1; | |
49 | } | |
50 | ||
51 | rewind (fp); | |
52 | if (ferror (fp)) | |
53 | { | |
54 | printf ("rewind: %m\n"); | |
55 | return 1; | |
56 | } | |
57 | ||
58 | c = fgetwc (fp); assert (c == L'1'); | |
59 | ||
60 | if (fsetpos (fp, &pos) == EOF) | |
61 | { | |
62 | printf ("fsetpos: %m\n"); | |
63 | return 1; | |
64 | } | |
65 | ||
66 | c = fgetwc (fp); | |
67 | if (c != L'3') | |
68 | { | |
69 | puts ("fsetpos failed"); | |
70 | return 1; | |
71 | } | |
72 | ||
73 | puts ("Test succeeded."); | |
74 | return 0; | |
75 | } |