XRogue: add and use more md_ functions.
Portable md_fileno() and md_unlink() have been added to state.c.
This commit is contained in:
parent
7d750a4410
commit
b2ebcf72c9
2 changed files with 39 additions and 12 deletions
|
|
@ -31,6 +31,8 @@ extern char version[];
|
||||||
extern unsigned char encstr[];
|
extern unsigned char encstr[];
|
||||||
extern int big_endian;
|
extern int big_endian;
|
||||||
|
|
||||||
|
int md_unlink(char *file);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
save_game()
|
save_game()
|
||||||
{
|
{
|
||||||
|
|
@ -95,7 +97,7 @@ gotfile:
|
||||||
if (save_file(savef) == FALSE) {
|
if (save_file(savef) == FALSE) {
|
||||||
fclose(savef);
|
fclose(savef);
|
||||||
msg("Cannot create save file.");
|
msg("Cannot create save file.");
|
||||||
unlink(file_name);
|
md_unlink(file_name);
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
fclose(savef);
|
fclose(savef);
|
||||||
|
|
@ -225,7 +227,7 @@ char **envp;
|
||||||
close(inf);
|
close(inf);
|
||||||
|
|
||||||
if (!wizard)
|
if (!wizard)
|
||||||
unlink(file);
|
md_unlink(file);
|
||||||
|
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
environ = envp;
|
environ = envp;
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,8 @@
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int md_fileno(FILE *fp);
|
||||||
|
|
||||||
#define READSTAT ((format_error == 0) && (read_error == 0))
|
#define READSTAT ((format_error == 0) && (read_error == 0))
|
||||||
#define WRITESTAT (write_error == 0)
|
#define WRITESTAT (write_error == 0)
|
||||||
|
|
||||||
|
|
@ -2924,8 +2926,9 @@ rs_write_scorefile(FILE *savef, struct sc_ent *entries, int count)
|
||||||
rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
|
rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
|
||||||
{
|
{
|
||||||
int i,available = 0;
|
int i,available = 0;
|
||||||
|
int sfd = md_fileno(savef);
|
||||||
|
|
||||||
rs_read_int(fileno(savef), &available);
|
rs_read_int(sfd, &available);
|
||||||
|
|
||||||
if (end_of_file)
|
if (end_of_file)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
@ -2935,15 +2938,15 @@ rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
|
||||||
|
|
||||||
for(i = 0; i < count; i++)
|
for(i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
rs_read_ulong(fileno(savef), &entries[i].sc_score);
|
rs_read_ulong(sfd, &entries[i].sc_score);
|
||||||
rs_read(fileno(savef), entries[i].sc_name, sizeof(entries[i].sc_name));
|
rs_read(sfd, entries[i].sc_name, sizeof(entries[i].sc_name));
|
||||||
rs_read(fileno(savef), entries[i].sc_system, sizeof(entries[i].sc_system));
|
rs_read(sfd, entries[i].sc_system, sizeof(entries[i].sc_system));
|
||||||
rs_read(fileno(savef), entries[i].sc_login, sizeof(entries[i].sc_login));
|
rs_read(sfd, entries[i].sc_login, sizeof(entries[i].sc_login));
|
||||||
rs_read_short(fileno(savef), &entries[i].sc_flags);
|
rs_read_short(sfd, &entries[i].sc_flags);
|
||||||
rs_read_short(fileno(savef), &entries[i].sc_level);
|
rs_read_short(sfd, &entries[i].sc_level);
|
||||||
rs_read_short(fileno(savef), &entries[i].sc_ctype);
|
rs_read_short(sfd, &entries[i].sc_ctype);
|
||||||
rs_read_short(fileno(savef), &entries[i].sc_monster);
|
rs_read_short(sfd, &entries[i].sc_monster);
|
||||||
rs_read_short(fileno(savef), &entries[i].sc_quest);
|
rs_read_short(sfd, &entries[i].sc_quest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
|
@ -3469,3 +3472,25 @@ md_normaluser(void)
|
||||||
setgid(getgid());
|
setgid(getgid());
|
||||||
#endif
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue