diff arogue7/main.c @ 279:d3968e9cb98d

Use C stdio functions for score files and save files. Switching from Unix file descriptor operations to C standard FILE* functions will reduce portability problems.
author John "Elwin" Edwards
date Fri, 15 Sep 2017 19:57:54 -0400
parents 3d4252fa2ed3
children 827441d05b3e
line wrap: on
line diff
--- a/arogue7/main.c	Sun Sep 10 17:30:13 2017 -0400
+++ b/arogue7/main.c	Fri Sep 15 19:57:54 2017 -0400
@@ -16,6 +16,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#include <errno.h>
 #ifdef BSD
 #include <sys/time.h>
 #else
@@ -551,10 +552,20 @@
 }
 
 void
+reopen_score(void)
+{
+    if (scoreboard != NULL)
+        fclose(scoreboard);
+    scoreboard = fopen(score_file, "r+");
+    if (scoreboard == NULL && errno == ENOENT)
+        scoreboard = fopen(score_file, "w+");
+}
+
+void
 open_records(void)
 {
-    if (scorefd == -1)
-        md_reopen_score();
+    if (scoreboard == NULL)
+        reopen_score();
 #ifdef LOGFILE
     if (logfile == NULL)
         logfile = fopen(LOGFILE, "a");