Mercurial > hg > early-roguelike
diff rogue4/save.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 | 70aa5808c782 |
line wrap: on
line diff
--- a/rogue4/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -23,7 +23,7 @@ void save_file(FILE *savef); extern int rs_save_file(FILE *savef); -extern int rs_restore_file(int inf); +extern int rs_restore_file(FILE *inf); typedef struct stat STAT; @@ -165,9 +165,9 @@ /* * close any open score file */ - if (fd >= 0) { - close(fd); - fd = -1; + if (score_file != NULL) { + fclose(score_file); + score_file = NULL; } move(LINES-1, 0); refresh(); @@ -197,7 +197,7 @@ bool restore(char *file, char **envp) { - register int inf; + FILE *inf; register bool syml; extern char **environ; char buf[MAXSTR]; @@ -214,7 +214,7 @@ signal(SIGTSTP, SIG_IGN); #endif - if ((inf = open(file, 0)) < 0) + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) { @@ -234,7 +234,7 @@ return FALSE; } - fstat(inf, &sbuf2); + stat(file, &sbuf2); fflush(stdout); syml = issymlink(file); @@ -348,13 +348,13 @@ * Perform an encrypted read */ int -encread(void *starta, int size, int inf) +encread(void *starta, int size, FILE *inf) { register char *ep; register int read_size; register char *start = (char *) starta; - if ((read_size = read(inf, start, size)) == -1 || read_size == 0) + if ((read_size = fread(start, 1, size, inf)) == 0) return read_size; ep = encstr;