comparison srogue/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 17005af49963
comparison
equal deleted inserted replaced
278:c222f9d56776 279:d3968e9cb98d
19 #include <string.h> 19 #include <string.h>
20 #include <time.h> 20 #include <time.h>
21 #include <fcntl.h> 21 #include <fcntl.h>
22 #include <stdio.h> 22 #include <stdio.h>
23 #include <limits.h> 23 #include <limits.h>
24 #include <errno.h>
24 #include <sys/stat.h> 25 #include <sys/stat.h>
25 #include "rogue.h" 26 #include "rogue.h"
26 27
27 #ifdef ATT 28 #ifdef ATT
28 #include <time.h> 29 #include <time.h>
35 #include "rogue.ext" 36 #include "rogue.ext"
36 37
37 char *roguehome(void); 38 char *roguehome(void);
38 void open_records(void); 39 void open_records(void);
39 40
40 extern int scorefd; 41 extern FILE *scoreboard;
41 extern FILE *logfile; 42 extern FILE *logfile;
42 43
43 int 44 int
44 main(int argc, char *argv[], char *envp[]) 45 main(int argc, char *argv[], char *envp[])
45 { 46 {
478 } 479 }
479 480
480 void 481 void
481 open_records(void) 482 open_records(void)
482 { 483 {
483 if (scorefd < 0) 484 if (scoreboard == NULL)
484 scorefd = open(scorefile, O_RDWR | O_CREAT, 0666); 485 scoreboard = fopen(scorefile, "r+");
486 if (scoreboard == NULL && errno == ENOENT) {
487 scoreboard = fopen(scorefile, "w+");
488 }
485 #ifdef LOGFILE 489 #ifdef LOGFILE
486 if (logfile == NULL) 490 if (logfile == NULL)
487 logfile = fopen(LOGFILE, "a"); 491 logfile = fopen(LOGFILE, "a");
488 #endif 492 #endif
489 } 493 }