malloc/Makefile: Split and sort tests
[glibc.git] / libio / bug-mmap-fflush.c
blob3f99222eefa7d4c3a925e887ee53d495f9a9402d
1 /* Test for bug in fflush synchronization behavior. */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
7 #include <support/xstdlib.h>
9 static char *fname;
11 static void prepare (void);
12 #define PREPARE(argc, argv) prepare ()
15 #define TEST_FUNCTION do_test ()
16 static int do_test (void);
17 #include "../test-skeleton.c"
20 static void
21 prepare (void)
23 int fd = create_temp_file ("bug-mmap-fflush.", &fname);
24 if (fd == -1)
25 exit (3);
26 /* We don't need the descriptor. */
27 close (fd);
31 static int
32 do_test (void)
34 FILE *f;
35 off_t o;
36 char buffer[1024];
38 snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname);
39 xsystem (buffer);
41 f = fopen (fname, "r");
42 fseek (f, 0, SEEK_END);
43 o = ftello (f);
44 fseek (f, 0, SEEK_SET);
45 fflush (f);
46 snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname);
47 xsystem (buffer);
49 fseek (f, o, SEEK_SET);
50 if (fgets (buffer, 1024, f) == NULL)
51 exit (1);
52 if (strncmp (buffer, "From ", 5) != 0)
53 exit (1);
54 fclose (f);
55 exit (0);