comparison rogue4/mach_dep.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 1b73a8641b37
children 6376b514a30b
comparison
equal deleted inserted replaced
278:c222f9d56776 279:d3968e9cb98d
35 #include <time.h> 35 #include <time.h>
36 #include <signal.h> 36 #include <signal.h>
37 #include <sys/stat.h> 37 #include <sys/stat.h>
38 #include <fcntl.h> 38 #include <fcntl.h>
39 #include <string.h> 39 #include <string.h>
40 #include <errno.h>
40 #include "rogue.h" 41 #include "rogue.h"
41 42
42 int num_checks; /* times we've gone over in checkout() */ 43 int num_checks; /* times we've gone over in checkout() */
43 44
44 #ifdef SCOREFILE 45 #ifdef SCOREFILE
78 */ 79 */
79 void 80 void
80 open_score(void) 81 open_score(void)
81 { 82 {
82 #ifdef SCOREFILE 83 #ifdef SCOREFILE
83 fd = open(SCOREFILE, O_RDWR | O_CREAT, 0666 ); 84 score_file = fopen(SCOREFILE, "r+");
85 if ((score_file == NULL) && (errno == ENOENT)) {
86 score_file = fopen(SCOREFILE, "w+");
87 }
84 #else 88 #else
85 fd = -1; 89 score_file = NULL;
86 #endif 90 #endif
87 if (!use_savedir) 91 if (!use_savedir)
88 md_normaluser(); 92 md_normaluser();
89 return; 93 return;
90 } 94 }
91 95
92 void 96 void
93 open_log(void) 97 open_log(void)
94 { 98 {
95 #ifdef LOGFILE 99 #ifdef LOGFILE
96 lfd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT, 0666); 100 log_file = fopen(LOGFILE, "a");
97 #else 101 #else
98 lfd = -1; 102 log_file = NULL;
99 #endif 103 #endif
100 return; 104 return;
101 } 105 }
102 106
103 /* 107 /*