Back to index

glibc  2.9
bug-mmap-fflush.c
Go to the documentation of this file.
00001 /* Test for bug in fflush synchronization behavior.  */
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 
00008 static char *fname;
00009 
00010 static void prepare (void);
00011 #define PREPARE(argc, argv) prepare ()
00012 
00013 
00014 #define TEST_FUNCTION do_test ()
00015 static int do_test (void);
00016 #include "../test-skeleton.c"
00017 
00018 
00019 static void
00020 prepare (void)
00021 {
00022   int fd = create_temp_file ("bug-mmap-fflush.", &fname);
00023   if (fd == -1)
00024     exit (3);
00025   /* We don't need the descriptor.  */
00026   close (fd);
00027 }
00028 
00029 
00030 static int
00031 do_test (void)
00032 {
00033   FILE *f;
00034   off_t o;
00035   char buffer[1024];
00036 
00037   snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname);
00038   system (buffer);
00039   f = fopen (fname, "r");
00040   fseek (f, 0, SEEK_END);
00041   o = ftello (f);
00042   fseek (f, 0, SEEK_SET);
00043   fflush (f);
00044   snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname);
00045   system (buffer);
00046   fseek (f, o, SEEK_SET);
00047   if (fgets (buffer, 1024, f) == NULL)
00048     exit (1);
00049   if (strncmp (buffer, "From ", 5) != 0)
00050     exit (1);
00051   fclose (f);
00052   exit (0);
00053 }