]> git.cworth.org Git - mnemon/blobdiff - mnemon.c
Add an fsync (Ted T'so would be pleased)
[mnemon] / mnemon.c
index bbc6456b60f9b9c8c4e78c9dfdfc84da36ce723b..5ce736433eed2cff4c931dde86a39c490f8f15f0 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -26,6 +26,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
+#include <unistd.h>
 #include <dirent.h>
 #include <errno.h>
 #include <string.h>
@@ -730,6 +731,7 @@ mnemon_save (mnemon_t *mnemon)
 
        category_print (category, file);
 
+       fsync (fileno (file));
        fclose (file);
 
        err = rename (lock_filename, filename);
@@ -1184,17 +1186,13 @@ mnemon_do_challenges (mnemon_t *mnemon)
     } while (mnemon->to_introduce ||
             mnemon->unlearned ||
             mnemon->to_master > 0);
-
-    printf ("Great job.\nHere are your current results:\n");
-    mnemon_print_histogram (mnemon, NULL, 0);
-    response = readline ("Press enter to quit.\n");
-    free (response);
 }
 
 int
 main (int argc, char *argv[])
 {
     mnemon_t mnemon;
+    char *response;
 
     srand (time (NULL));
 
@@ -1208,5 +1206,15 @@ main (int argc, char *argv[])
 
     mnemon_fini (&mnemon);
 
+    mnemon_init (&mnemon);
+    mnemon_load (&mnemon);
+
+    printf ("Great job.\nHere are your current results:\n");
+    mnemon_print_histogram (&mnemon, NULL, 0);
+    response = readline ("Press enter to quit.\n");
+    free (response);
+
+    mnemon_fini (&mnemon);
+
     return 0;
 }