diff arogue7/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 f9ef86cf22b2
children 0250220d8cdd
line wrap: on
line diff
--- a/arogue7/rip.c	Sun Sep 10 17:30:13 2017 -0400
+++ b/arogue7/rip.c	Fri Sep 15 19:57:54 2017 -0400
@@ -46,9 +46,6 @@
 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 @@
     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 @@
     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 @@
     /* 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 @@
 		errors++;
 	
 	if (errors) {
-	    close(outfd);
+	    fclose(scoreboard);
 	    free(compatstr);
 	    return;
 	}
@@ -646,7 +640,7 @@
 	}
 /*	if (prflags == EDITSCORE) endwin();*/	/* End editing windowing */
     }
-    lseek(outfd, 0L, 0);
+    fseek(scoreboard, 0L, SEEK_SET);
     /*
      * Update the list file
      */
@@ -654,17 +648,17 @@
     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);
 }
 
 /*