comparison xrogue/state.c @ 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
comparison
equal deleted inserted replaced
205:6e6fb0955095 206:a3d90e31a001
82 #include "mach_dep.h" 82 #include "mach_dep.h"
83 83
84 #if defined(_WIN32) 84 #if defined(_WIN32)
85 #include <process.h> 85 #include <process.h>
86 #endif 86 #endif
87
88 int md_fileno(FILE *fp);
87 89
88 #define READSTAT ((format_error == 0) && (read_error == 0)) 90 #define READSTAT ((format_error == 0) && (read_error == 0))
89 #define WRITESTAT (write_error == 0) 91 #define WRITESTAT (write_error == 0)
90 92
91 int read_error = FALSE; 93 int read_error = FALSE;
2922 } 2924 }
2923 2925
2924 rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count) 2926 rs_read_scorefile(FILE *savef, struct sc_ent *entries, int count)
2925 { 2927 {
2926 int i,available = 0; 2928 int i,available = 0;
2927 2929 int sfd = md_fileno(savef);
2928 rs_read_int(fileno(savef), &available); 2930
2931 rs_read_int(sfd, &available);
2929 2932
2930 if (end_of_file) 2933 if (end_of_file)
2931 return(-1); 2934 return(-1);
2932 2935
2933 if (available != count) 2936 if (available != count)
2934 return(-2); 2937 return(-2);
2935 2938
2936 for(i = 0; i < count; i++) 2939 for(i = 0; i < count; i++)
2937 { 2940 {
2938 rs_read_ulong(fileno(savef), &entries[i].sc_score); 2941 rs_read_ulong(sfd, &entries[i].sc_score);
2939 rs_read(fileno(savef), entries[i].sc_name, sizeof(entries[i].sc_name)); 2942 rs_read(sfd, entries[i].sc_name, sizeof(entries[i].sc_name));
2940 rs_read(fileno(savef), entries[i].sc_system, sizeof(entries[i].sc_system)); 2943 rs_read(sfd, entries[i].sc_system, sizeof(entries[i].sc_system));
2941 rs_read(fileno(savef), entries[i].sc_login, sizeof(entries[i].sc_login)); 2944 rs_read(sfd, entries[i].sc_login, sizeof(entries[i].sc_login));
2942 rs_read_short(fileno(savef), &entries[i].sc_flags); 2945 rs_read_short(sfd, &entries[i].sc_flags);
2943 rs_read_short(fileno(savef), &entries[i].sc_level); 2946 rs_read_short(sfd, &entries[i].sc_level);
2944 rs_read_short(fileno(savef), &entries[i].sc_ctype); 2947 rs_read_short(sfd, &entries[i].sc_ctype);
2945 rs_read_short(fileno(savef), &entries[i].sc_monster); 2948 rs_read_short(sfd, &entries[i].sc_monster);
2946 rs_read_short(fileno(savef), &entries[i].sc_quest); 2949 rs_read_short(sfd, &entries[i].sc_quest);
2947 } 2950 }
2948 2951
2949 return(0); 2952 return(0);
2950 } 2953 }
2951 2954
3467 #ifndef _WIN32 3470 #ifndef _WIN32
3468 setuid(getuid()); 3471 setuid(getuid());
3469 setgid(getgid()); 3472 setgid(getgid());
3470 #endif 3473 #endif
3471 } 3474 }
3475
3476 int
3477 md_fileno(FILE *fp)
3478 {
3479 #ifdef _WIN32
3480 return( _fileno(fp) );
3481 #else
3482 return( fileno(fp) );
3483 #endif
3484 }
3485
3486 int
3487 md_unlink(char *file)
3488 {
3489 #ifdef _WIN32
3490 chmod(file, 0600);
3491 return( _unlink(file) );
3492 #else
3493 return(unlink(file));
3494 #endif
3495 }
3496