1 /* Test case for bug with mmap stdio read past end of file. */
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
;
15 static const char text1
[] = "hello\n";
20 int temp_fd
= create_temp_file ("tst-mmap-offend.", &temp_file
);
22 error (1, errno
, "cannot create temporary file");
25 ssize_t cc
= write (temp_fd
, text1
, sizeof text1
- 1);
26 if (cc
!= sizeof text1
- 1)
27 error (1, errno
, "cannot write to temporary file");
35 unsigned char buffer
[8192];
37 FILE *f
= fopen (temp_file
, "rm");
46 cc
= fread (buffer
, 1, sizeof (buffer
), f
);
47 printf ("fread %zu: \"%.*s\"\n", cc
, (int) cc
, buffer
);
48 if (cc
!= sizeof text1
- 1)
54 if (fseek (f
, 2048, SEEK_SET
) != 0)
56 perror ("fseek off end");
60 if (fread (buffer
, 1, sizeof (buffer
), f
) != 0
61 || ferror (f
) || !feof (f
))
63 printf ("after fread error %d eof %d\n",
64 ferror (f
), feof (f
));
68 printf ("ftell %ld\n", ftell (f
));
70 if (fseek (f
, 0, SEEK_SET
) != 0)
72 perror ("fseek rewind");
76 cc
= fread (buffer
, 1, sizeof (buffer
), f
);
77 printf ("fread after rewind %zu: \"%.*s\"\n", cc
, (int) cc
, buffer
);
78 if (cc
!= sizeof text1
- 1)
80 perror ("fread after rewind");