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.
This commit is contained in:
John "Elwin" Edwards 2017-09-15 19:57:54 -04:00
parent f8d1f422c8
commit c661fd79d4
33 changed files with 426 additions and 439 deletions

View file

@ -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 @@ save_file(FILE *savef)
/*
* 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 @@ save_file(FILE *savef)
bool
restore(char *file, char **envp)
{
register int inf;
FILE *inf;
register bool syml;
extern char **environ;
char buf[MAXSTR];
@ -214,7 +214,7 @@ restore(char *file, char **envp)
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 @@ restore(char *file, char **envp)
return FALSE;
}
fstat(inf, &sbuf2);
stat(file, &sbuf2);
fflush(stdout);
syml = issymlink(file);
@ -348,13 +348,13 @@ encwrite(void *starta, int size, FILE *outf)
* 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;