1 /* Test program for ungetc/ftell interaction bug. */
5 #include <support/xunistd.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
;
19 int fd
= create_temp_file ("bug-ungetc.", &temp_file
);
22 printf ("cannot create temporary file: %m\n");
25 xwrite (fd
, pattern
, sizeof (pattern
));
38 f
= fopen (temp_file
, "rw");
41 for (i
= 0; i
< 3; i
++)
42 printf ("%c\n", getc (f
));
44 printf ("offset = %ld\n", offset
);
45 if (ungetc ('4', f
) != '4')
47 printf ("ungetc failed\n");
50 printf ("offset after ungetc = %ld\n", ftell (f
));
52 i
= fread ((void *) buf
, 4, (size_t) 1, f
);
53 printf ("read %d (%c), offset = %ld\n", i
, buf
[0], ftell (f
));
54 diff
= ftell (f
) - offset
;
57 printf ("ftell did not update properly. got %ld, expected 3\n", diff
);