Fix warning from latest GCC in tst-printf.c
[glibc.git] / libio / bug-mmap-fflush.c
blobd8aa58985aa0790c1267e7b00a281eec0238da6e
1 /* Test for bug in fflush synchronization behavior. */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
8 static char *fname;
10 static void prepare (void);
11 #define PREPARE(argc, argv) prepare ()
14 #define TEST_FUNCTION do_test ()
15 static int do_test (void);
16 #include "../test-skeleton.c"
19 static void
20 prepare (void)
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);
30 static int
31 do_test (void)
33 FILE *f;
34 off_t o;
35 char buffer[1024];
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);