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

@ -49,7 +49,6 @@ score(int amount, int flags, char monst)
register struct sc_ent *scp;
register int i;
register struct sc_ent *sc2;
register FILE *outf;
register int prflags = 0;
register void (*fp)(int);
register int uid;
@ -72,11 +71,6 @@ score(int amount, int flags, char monst)
start_score();
if (fd >= 0)
outf = md_fdopen(fd, "wb");
else
return;
for (scp = top_ten; scp <= &top_ten[9]; scp++)
{
scp->sc_score = 0;
@ -112,9 +106,9 @@ score(int amount, int flags, char monst)
#endif
for(i=0; i<10; i++)
{
encread((char *) &top_ten[i].sc_name, MAXSTR, fd);
encread((char *) &top_ten[i].sc_name, MAXSTR, score_file);
scoreline[0] = '\0';
encread((char *) scoreline, 100, fd);
encread((char *) scoreline, 100, score_file);
sscanf(scoreline, "%d %d %hd %hd %hd", &top_ten[i].sc_flags,
&top_ten[i].sc_uid, &top_ten[i].sc_monster, &top_ten[i].sc_score,
&top_ten[i].sc_level);
@ -209,7 +203,7 @@ score(int amount, int flags, char monst)
else
break;
}
fseek(outf, 0L, 0);
fseek(score_file, 0L, 0);
/*
* Update the list file
*/
@ -223,33 +217,28 @@ score(int amount, int flags, char monst)
for(i=0; i<10; i++)
{
encwrite((char *) &top_ten[i].sc_name, MAXSTR, outf);
encwrite((char *) &top_ten[i].sc_name, MAXSTR, score_file);
sprintf(scoreline," %d %d %hd %hd %hd \n",
top_ten[i].sc_flags, top_ten[i].sc_uid,
top_ten[i].sc_monster, top_ten[i].sc_score,
top_ten[i].sc_level);
encwrite((char *) scoreline, 100, outf);
encwrite((char *) scoreline, 100, score_file);
}
unlock_sc();
signal(SIGINT, fp);
}
}
fclose(outf);
fclose(score_file);
}
void writelog(int amount, int flags, char monst)
{
FILE *logfi;
char logmessage[220], ltemp[80];
char *killer;
if (noscore)
return;
#ifdef LOGFILE
if (lfd >= 0)
logfi = md_fdopen(lfd, "a");
else
return;
if (logfi == NULL)
if (log_file == NULL)
return;
/* otherwise writing should work */
sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
@ -283,13 +272,13 @@ void writelog(int amount, int flags, char monst)
}
else
{
fclose(logfi);
fclose(log_file);
return;
}
/* then write */
fprintf(logfi, "%s", logmessage);
fclose(logfi);
fprintf(log_file, "%s", logmessage);
fclose(log_file);
#endif
return;
}