re_search_internal: Avoid overflow in computing re_malloc buffer size
[glibc.git] / libio / bug-wsetpos.c
blobccb22a4b6225df0b2b7a5c0ee6458cab370c6b29
1 /* Test program for fsetpos on a wide character stream. */
3 #include <assert.h>
4 #include <stdio.h>
5 #include <wchar.h>
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>
13 static const char pattern[] = "12345";
14 static char *temp_file;
16 static void
17 do_prepare (void)
19 int fd = create_temp_file ("bug-wsetpos.", &temp_file);
20 if (fd == -1)
22 printf ("cannot create temporary file: %m\n");
23 exit (1);
25 write (fd, pattern, sizeof (pattern));
26 close (fd);
29 static int
30 do_test (void)
32 FILE *fp = fopen (temp_file, "r");
33 fpos_t pos;
34 wchar_t c;
36 if (fp == NULL)
38 printf ("fdopen: %m\n");
39 return 1;
42 c = fgetwc (fp); assert (c == L'1');
43 c = fgetwc (fp); assert (c == L'2');
45 if (fgetpos (fp, &pos) == EOF)
47 printf ("fgetpos: %m\n");
48 return 1;
51 rewind (fp);
52 if (ferror (fp))
54 printf ("rewind: %m\n");
55 return 1;
58 c = fgetwc (fp); assert (c == L'1');
60 if (fsetpos (fp, &pos) == EOF)
62 printf ("fsetpos: %m\n");
63 return 1;
66 c = fgetwc (fp);
67 if (c != L'3')
69 puts ("fsetpos failed");
70 return 1;
73 puts ("Test succeeded.");
74 return 0;