1 /* Test program for ungetc/ftell interaction bug. */
5 static void do_prepare (void);
6 #define PREPARE(argc, argv) do_prepare ()
7 static int do_test (void);
8 #define TEST_FUNCTION do_test ()
9 #include <test-skeleton.c>
11 static const char pattern
[] = "12345";
12 static char *temp_file
;
17 int fd
= create_temp_file ("bug-ungetc.", &temp_file
);
20 printf ("cannot create temporary file: %m\n");
23 write (fd
, pattern
, sizeof (pattern
));
36 f
= fopen (temp_file
, "rw");
39 for (i
= 0; i
< 3; i
++)
40 printf ("%c\n", getc (f
));
42 printf ("offset = %ld\n", offset
);
43 if (ungetc ('4', f
) != '4')
45 printf ("ungetc failed\n");
48 printf ("offset after ungetc = %ld\n", ftell (f
));
50 i
= fread ((void *) buf
, 4, (size_t) 1, f
);
51 printf ("read %d (%c), offset = %ld\n", i
, buf
[0], ftell (f
));
52 diff
= ftell (f
) - offset
;
55 printf ("ftell did not update properly. got %ld, expected 3\n", diff
);