diff srogue/main.c @ 173:78fa1d0e5d25

srogue: open the score and log files when the program starts. Super-Rogue can now use the same privilege-dropping scheme as the other games.
author John "Elwin" Edwards
date Sat, 01 Aug 2015 15:12:11 -0400
parents e6c8652473fe
children 1863409c44cf
line wrap: on
line diff
--- a/srogue/main.c	Thu Jul 23 19:28:12 2015 -0400
+++ b/srogue/main.c	Sat Aug 01 15:12:11 2015 -0400
@@ -34,6 +34,11 @@
 
 #include "rogue.ext"
 
+void open_records(void);
+
+extern int scorefd;
+extern FILE *logfile;
+
 main(argc, argv, envp)
 char **argv;
 char **envp;
@@ -70,6 +75,7 @@
 		strcat(scorefile,"/");
 	strcat(scorefile, "srogue.scr");
 #endif
+        open_records();
 
 	if(argc >= 2 && strcmp(argv[1], "-s") == 0)
 	{
@@ -472,3 +478,14 @@
     return(NULL);
 }
 
+void
+open_records(void)
+{
+    if (scorefd < 0)
+	scorefd = open(scorefile, O_RDWR | O_CREAT, 0666);
+#ifdef LOGFILE
+    if (logfile == NULL)
+        logfile = fopen(LOGFILE, "a");
+#endif
+}
+