# HG changeset patch # User John "Elwin" Edwards # Date 1439493321 14400 # Node ID a3d90e31a001398bcf1190a5b952ca24c7f72eb3 # Parent 6e6fb09550956810d009125eb230ebd7a6583e5a XRogue: add and use more md_ functions. Portable md_fileno() and md_unlink() have been added to state.c. diff -r 6e6fb0955095 -r a3d90e31a001 xrogue/save.c --- 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; diff -r 6e6fb0955095 -r a3d90e31a001 xrogue/state.c --- 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 #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 +} +