Mercurial > hg > early-roguelike
diff xrogue/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 | f54901b9c39b |
children |
line wrap: on
line diff
--- a/xrogue/save.c Sun Sep 10 17:30:13 2017 -0400 +++ b/xrogue/save.c Fri Sep 15 19:57:54 2017 -0400 @@ -32,9 +32,9 @@ extern int big_endian; bool rs_write_int(FILE *savef, int c); -bool rs_read_int(int inf, int *i); +bool rs_read_int(FILE *inf, int *i); bool rs_save_file(FILE *savef); -bool rs_restore_file(int inf); +bool rs_restore_file(FILE *inf); int md_unlink(char *file); bool save_file(FILE *savef); @@ -158,7 +158,7 @@ bool restore(char *file, char *envp[]) { - register int inf; + FILE *inf; extern char **environ; char buf[LINELEN]; int endian = 0x01020304; @@ -167,7 +167,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) { @@ -224,11 +224,11 @@ { endwin(); printf("Cannot restore file\n"); - close(inf); + fclose(inf); return(FALSE); } - close(inf); + fclose(inf); if (!wizard) md_unlink(file); @@ -293,7 +293,7 @@ */ long -encread(char *start, unsigned long size, int inf) +encread(char *start, unsigned long size, FILE *inf) { register unsigned char *ep; register int rd_siz; @@ -303,8 +303,8 @@ while (total_read < size) { rd_siz = ENCRBSIZ; rd_siz = ((size-total_read) > ENCRBSIZ) ? ENCRBSIZ : (size-total_read); - rd_siz = read(inf,&start[total_read],rd_siz); - if(rd_siz==-1 || rd_siz==0) + rd_siz = fread(&start[total_read], 1, rd_siz, inf); + if(rd_siz==0) break; total_read += rd_siz; }