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