changeset 206:a3d90e31a001

XRogue: add and use more md_ functions. Portable md_fileno() and md_unlink() have been added to state.c.
author John "Elwin" Edwards
date Thu, 13 Aug 2015 15:15:21 -0400
parents 6e6fb0955095
children 3def5e487faa
files xrogue/save.c xrogue/state.c
diffstat 2 files changed, 40 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/xrogue/save.c	Thu Aug 13 14:57:26 2015 -0400
+++ b/xrogue/save.c	Thu Aug 13 15:15:21 2015 -0400
@@ -31,6 +31,8 @@
 extern unsigned char encstr[];
 extern int big_endian;
 
+int md_unlink(char *file);
+
 bool
 save_game()
 {
@@ -95,7 +97,7 @@
     if (save_file(savef) == FALSE) {
         fclose(savef);
         msg("Cannot create save file.");
-        unlink(file_name);
+        md_unlink(file_name);
         return(FALSE);
     }
     fclose(savef);
@@ -225,7 +227,7 @@
     close(inf);
 
     if (!wizard)
-        unlink(file);
+        md_unlink(file);
  
     mpos = 0;
     environ = envp;
--- a/xrogue/state.c	Thu Aug 13 14:57:26 2015 -0400
+++ b/xrogue/state.c	Thu Aug 13 15:15:21 2015 -0400
@@ -85,6 +85,8 @@
 #include <process.h>
 #endif
 
+int md_fileno(FILE *fp);
+
 #define READSTAT ((format_error == 0) && (read_error == 0))
 #define WRITESTAT (write_error == 0)
 
@@ -2924,8 +2926,9 @@
 rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
 {
     int i,available = 0;
-
-    rs_read_int(fileno(savef), &available);
+    int sfd = md_fileno(savef);
+
+    rs_read_int(sfd, &available);
 
     if (end_of_file)
        return(-1);
@@ -2935,15 +2938,15 @@
 
     for(i = 0; i < count; i++)
     {
-        rs_read_ulong(fileno(savef), &entries[i].sc_score);
-        rs_read(fileno(savef), entries[i].sc_name, sizeof(entries[i].sc_name));
-        rs_read(fileno(savef), entries[i].sc_system, sizeof(entries[i].sc_system));
-        rs_read(fileno(savef), entries[i].sc_login, sizeof(entries[i].sc_login));
-        rs_read_short(fileno(savef), &entries[i].sc_flags);
-        rs_read_short(fileno(savef), &entries[i].sc_level);
-        rs_read_short(fileno(savef), &entries[i].sc_ctype);
-        rs_read_short(fileno(savef), &entries[i].sc_monster);
-        rs_read_short(fileno(savef), &entries[i].sc_quest);
+        rs_read_ulong(sfd, &entries[i].sc_score);
+        rs_read(sfd, entries[i].sc_name, sizeof(entries[i].sc_name));
+        rs_read(sfd, entries[i].sc_system, sizeof(entries[i].sc_system));
+        rs_read(sfd, entries[i].sc_login, sizeof(entries[i].sc_login));
+        rs_read_short(sfd, &entries[i].sc_flags);
+        rs_read_short(sfd, &entries[i].sc_level);
+        rs_read_short(sfd, &entries[i].sc_ctype);
+        rs_read_short(sfd, &entries[i].sc_monster);
+        rs_read_short(sfd, &entries[i].sc_quest);
     }
 
     return(0);
@@ -3469,3 +3472,25 @@
     setgid(getgid());
 #endif
 }
+
+int
+md_fileno(FILE *fp)
+{
+#ifdef _WIN32
+    return( _fileno(fp) );
+#else
+    return( fileno(fp) );
+#endif
+}
+
+int
+md_unlink(char *file)
+{
+#ifdef _WIN32
+    chmod(file, 0600);
+    return( _unlink(file) );
+#else
+    return(unlink(file));
+#endif
+}
+