1 /* Test program for synchronization of stdio state with file after EOF. */
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 char *temp_file
;
16 static char text1
[] = "Line the first\n";
17 static char text2
[] = "Line the second\n";
22 temp_fd
= create_temp_file ("tst-mmap-eofsync.", &temp_file
);
24 error (1, errno
, "cannot create temporary file");
27 ssize_t cc
= write (temp_fd
, text1
, sizeof text1
- 1);
28 if (cc
!= sizeof text1
- 1)
29 error (1, errno
, "cannot write to temporary file");
41 f
= fopen (temp_file
, "rm");
48 if (fgets (buf
, sizeof buf
, f
) == NULL
)
54 if (strcmp (buf
, text1
))
56 printf ("read \"%s\", expected \"%s\"\n", buf
, text1
);
60 printf ("feof = %d, ferror = %d immediately after fgets\n",
61 feof (f
), ferror (f
));
66 printf ("fgetc -> EOF (feof = %d, ferror = %d)\n",
67 feof (f
), ferror (f
));
70 printf ("fgetc returned %o (feof = %d, ferror = %d)\n",
71 c
, feof (f
), ferror (f
));
76 c
= write (temp_fd
, text2
, sizeof text2
- 1);
77 if (c
== sizeof text2
- 1)
78 printf ("wrote more to file\n");
81 printf ("wrote %d != %zd (%m)\n", c
, sizeof text2
- 1);
85 if (fgets (buf
, sizeof buf
, f
) == NULL
)
87 printf ("second fgets fails: feof = %d, ferror = %d (%m)\n",
88 feof (f
), ferror (f
));
90 if (fgets (buf
, sizeof buf
, f
) == NULL
)
92 printf ("retry fgets fails: feof = %d, ferror = %d (%m)\n",
93 feof (f
), ferror (f
));
97 if (result
== 0 && strcmp (buf
, text2
))
99 printf ("second time read \"%s\", expected \"%s\"\n", buf
, text2
);