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