bug-mmap-fflush.c 1011 B

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