bug-mmap-fflush.c 1.0 KB

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