Mercurial > hg > early-roguelike
diff arogue5/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/arogue5/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/arogue5/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -151,7 +151,7 @@ bool restore(char *file, char **envp) { - register int inf; + FILE *inf; #ifndef _AIX extern char **environ; #endif @@ -162,7 +162,7 @@ if (strcmp(file, "-r") == 0) file = file_name; - if ((inf = open(file, O_RDONLY)) < 0) + if ((inf = fopen(file, "r")) == NULL) { if (use_savedir && errno == ENOENT) { @@ -189,7 +189,7 @@ encread(buf, 80, inf); sscanf(buf, "%d x %d\n", &oldline, &oldcol); - fstat(inf, &sbuf2); + stat(file, &sbuf2); fflush(stdout); /* @@ -235,7 +235,7 @@ if (!wizard) { if (md_unlink(file) < 0) { - close(inf); /* only close if system insists */ + fclose(inf); /* only close if system insists */ if (md_unlink(file) < 0) { endwin(); printf("\nCannot unlink file\n"); @@ -287,12 +287,12 @@ * perform an encrypted read */ int -encread(char *start, unsigned int size, int inf) +encread(char *start, unsigned int size, FILE *inf) { register char *ep; register int read_size; - 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;