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

@ -46,9 +46,6 @@ extern struct uwdata wdata, oldwin;
extern char oldtext[WTXTNUM][WTXTLEN];
#endif
extern int scorefd;
extern FILE *logfile;
#ifdef NUMNET
/* Network machines (for mutual score keeping) */
static struct network Network[NUMNET] = {
@ -256,10 +253,8 @@ score(unsigned long amount, int flags, short monst)
register struct sc_ent *scp;
register int i;
register struct sc_ent *sc2;
register int outfd;
register char *killer;
register int prflags = 0;
register int fd;
short upquest, wintype, uplevel, uptype; /* For network updating */
char upsystem[SYSLEN], uplogin[LOGLEN];
char *thissys; /* Holds the name of this system */
@ -290,11 +285,10 @@ score(unsigned long amount, int flags, short monst)
purse = 0; /* Steal all the gold */
/*
* Open file and read list
* Read list
*/
if ((fd = scorefd) < 0) return;
outfd = fd;
if (scoreboard == NULL) return;
#ifndef SYSTEM
thissys = md_gethostname();
@ -347,10 +341,10 @@ score(unsigned long amount, int flags, short monst)
/* Read the score and convert it to a compatible format */
for(i = 0; i < NUMSCORE; i++)
{
encread(top_ten[i].sc_name, NAMELEN, fd);
encread(top_ten[i].sc_system, SYSLEN, fd);
encread(top_ten[i].sc_login, LOGLEN, fd);
encread(scoreline, 100, fd);
encread(top_ten[i].sc_name, NAMELEN, scoreboard);
encread(top_ten[i].sc_system, SYSLEN, scoreboard);
encread(top_ten[i].sc_login, LOGLEN, scoreboard);
encread(scoreline, 100, scoreboard);
sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n",
&top_ten[i].sc_score, &top_ten[i].sc_flags,
&top_ten[i].sc_level, &top_ten[i].sc_ctype,
@ -383,7 +377,7 @@ score(unsigned long amount, int flags, short monst)
errors++;
if (errors) {
close(outfd);
fclose(scoreboard);
free(compatstr);
return;
}
@ -646,7 +640,7 @@ score(unsigned long amount, int flags, short monst)
}
/* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */
}
lseek(outfd, 0L, 0);
fseek(scoreboard, 0L, SEEK_SET);
/*
* Update the list file
*/
@ -654,17 +648,17 @@ score(unsigned long amount, int flags, short monst)
for(i = 0; i < NUMSCORE; i++)
{
memset(scoreline,0,100);
encwrite(top_ten[i].sc_name, NAMELEN, outfd);
encwrite(top_ten[i].sc_system, SYSLEN, outfd);
encwrite(top_ten[i].sc_login, LOGLEN, outfd);
encwrite(top_ten[i].sc_name, NAMELEN, scoreboard);
encwrite(top_ten[i].sc_system, SYSLEN, scoreboard);
encwrite(top_ten[i].sc_login, LOGLEN, scoreboard);
sprintf(scoreline, " %lu %hd %hd %hd %hd %hd \n",
top_ten[i].sc_score, top_ten[i].sc_flags,
top_ten[i].sc_level, top_ten[i].sc_ctype,
top_ten[i].sc_monster, top_ten[i].sc_quest);
encwrite(scoreline,100,outfd);
encwrite(scoreline,100,scoreboard);
}
close(outfd);
fclose(scoreboard);
}
/*