summary refs log tree commit diff
path: root/libio/bug-mmap-fflush.c
blob: 984acb496b3fad3d8e5816066ba5cb9585bb9f83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Test for bug in fflush synchronization behavior.  */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (void)
{
  FILE *f;
  off_t o;
  char buffer [1024];

  system ("echo 'From foo@bar.com' > test");
  f = fopen ("test", "r");
  fseek (f, 0, SEEK_END);
  o = ftello (f);
  fseek (f, 0, SEEK_SET);
  fflush (f);
  system ("echo 'From bar@baz.edu' >> test");
  fseek (f, o, SEEK_SET);
  if (fgets (buffer, 1024, f) == NULL)
    abort ();
  if (strncmp (buffer, "From ", 5) != 0)
    abort ();
  fclose (f);
  exit (0);
}