Mercurial > hg > early-roguelike
diff rogue4/rip.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 | 23d2e2bf812f |
children | 0250220d8cdd |
line wrap: on
line diff
--- a/rogue4/rip.c Sun Sep 10 17:30:13 2017 -0400 +++ b/rogue4/rip.c Fri Sep 15 19:57:54 2017 -0400 @@ -49,7 +49,6 @@ 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 @@ 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 @@ #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 @@ else break; } - fseek(outf, 0L, 0); + fseek(score_file, 0L, 0); /* * Update the list file */ @@ -223,33 +217,28 @@ 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 @@ } 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; }