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
));
30 do_one_test (int mode
)
34 f
= fopen (temp_file
, "r");
37 printf ("could not open temporary file: %m\n");
41 if (mode
== 1 && ftell (f
) != 0)
43 printf ("first ftell returned wrong position %ld\n", ftell (f
));
47 if (fgetc (f
) != '1' || fgetc (f
) != '2')
49 puts ("fgetc failed");
53 if (mode
== 2 && ftell (f
) != 2)
55 printf ("second ftell returned wrong position %ld\n", ftell (f
));
59 if (ungetc ('6', f
) != '6')
61 puts ("ungetc failed");
67 printf ("third ftell returned wrong position %ld\n", ftell (f
));
73 puts ("fgetc failed");
79 printf ("fourth ftell returned wrong position %ld\n", ftell (f
));
92 for (mode
= 0; mode
<= 2; mode
++)
93 if (do_one_test (mode
))