lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Test for bug in fflush synchronization behavior. */ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | |
| 8 | static char *fname; |
| 9 | |
| 10 | static void prepare (void); |
| 11 | #define PREPARE(argc, argv) prepare () |
| 12 | |
| 13 | |
| 14 | #define TEST_FUNCTION do_test () |
| 15 | static int do_test (void); |
| 16 | #include "../test-skeleton.c" |
| 17 | |
| 18 | |
| 19 | static void |
| 20 | prepare (void) |
| 21 | { |
| 22 | int fd = create_temp_file ("bug-mmap-fflush.", &fname); |
| 23 | if (fd == -1) |
| 24 | exit (3); |
| 25 | /* We don't need the descriptor. */ |
| 26 | close (fd); |
| 27 | } |
| 28 | |
| 29 | |
| 30 | static int |
| 31 | do_test (void) |
| 32 | { |
| 33 | FILE *f; |
| 34 | off_t o; |
| 35 | char buffer[1024]; |
| 36 | |
| 37 | snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname); |
| 38 | system (buffer); |
| 39 | f = fopen (fname, "r"); |
| 40 | fseek (f, 0, SEEK_END); |
| 41 | o = ftello (f); |
| 42 | fseek (f, 0, SEEK_SET); |
| 43 | fflush (f); |
| 44 | snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname); |
| 45 | system (buffer); |
| 46 | fseek (f, o, SEEK_SET); |
| 47 | if (fgets (buffer, 1024, f) == NULL) |
| 48 | exit (1); |
| 49 | if (strncmp (buffer, "From ", 5) != 0) |
| 50 | exit (1); |
| 51 | fclose (f); |
| 52 | exit (0); |
| 53 | } |