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));
28 do_one_test (int mode)
32 f = fopen (temp_file, "r");
35 printf ("could not open temporary file: %m\n");
39 if (mode == 1 && ftell (f) != 0)
41 printf ("first ftell returned wrong position %ld\n", ftell (f));
45 if (fgetc (f) != '1' || fgetc (f) != '2')
47 puts ("fgetc failed");
51 if (mode == 2 && ftell (f) != 2)
53 printf ("second ftell returned wrong position %ld\n", ftell (f));
57 if (ungetc ('6', f) != '6')
59 puts ("ungetc failed");
65 printf ("third ftell returned wrong position %ld\n", ftell (f));
71 puts ("fgetc failed");
77 printf ("fourth ftell returned wrong position %ld\n", ftell (f));
90 for (mode = 0; mode <= 2; mode++)
91 if (do_one_test (mode))