stdio: Remove __libc_message alloca usage
[glibc.git] / libio / bug-wsetpos.c
blob0fc373ba490c4d408273a5ad5dcb37341a65cab5
1 /* Test program for fsetpos on a wide character stream. */
3 #include <assert.h>
4 #include <stdio.h>
5 #include <wchar.h>
7 #include <support/xunistd.h>
9 static void do_prepare (void);
10 #define PREPARE(argc, argv) do_prepare ()
11 static int do_test (void);
12 #define TEST_FUNCTION do_test ()
13 #include <test-skeleton.c>
15 static const char pattern[] = "12345";
16 static char *temp_file;
18 static void
19 do_prepare (void)
21 int fd = create_temp_file ("bug-wsetpos.", &temp_file);
22 if (fd == -1)
24 printf ("cannot create temporary file: %m\n");
25 exit (1);
27 xwrite (fd, pattern, sizeof (pattern));
28 close (fd);
31 static int
32 do_test (void)
34 FILE *fp = fopen (temp_file, "r");
35 fpos_t pos;
36 wchar_t c;
38 if (fp == NULL)
40 printf ("fdopen: %m\n");
41 return 1;
44 c = fgetwc (fp); assert (c == L'1');
45 c = fgetwc (fp); assert (c == L'2');
47 if (fgetpos (fp, &pos) == EOF)
49 printf ("fgetpos: %m\n");
50 return 1;
53 rewind (fp);
54 if (ferror (fp))
56 printf ("rewind: %m\n");
57 return 1;
60 c = fgetwc (fp); assert (c == L'1');
62 if (fsetpos (fp, &pos) == EOF)
64 printf ("fsetpos: %m\n");
65 return 1;
68 c = fgetwc (fp);
69 if (c != L'3')
71 puts ("fsetpos failed");
72 return 1;
75 puts ("Test succeeded.");
76 return 0;