Mercurial > hg > early-roguelike
diff srogue/state.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 | b49d8b963df3 |
children | e52a8a7ad4c5 |
line wrap: on
line diff
--- a/srogue/state.c Sun Sep 10 17:30:13 2017 -0400 +++ b/srogue/state.c Fri Sep 15 19:57:54 2017 -0400 @@ -70,7 +70,7 @@ #define READSTAT ((format_error == 0) && (read_error == 0)) #define WRITESTAT (write_error == 0) -int rs_read_int(int inf, int *i); +int rs_read_int(FILE *inf, int *i); int rs_write_int(FILE *savef, int c); int read_error = FALSE; @@ -105,13 +105,13 @@ * perform an encrypted read */ int -encread(void *starta, unsigned int size, int inf) +encread(void *starta, unsigned int size, FILE *inf) { register char *ep; register int read_size; register char *start = starta; - if ((read_size = read(inf, start, size)) == -1 || read_size == 0) + if ((read_size = fread(start, 1, size, inf)) == 0) return read_size; ep = encstr; @@ -466,7 +466,7 @@ } int -rs_read(int inf, void *ptr, int size) +rs_read(FILE *inf, void *ptr, int size) { int actual; @@ -497,7 +497,7 @@ } int -rs_read_char(int inf, char *c) +rs_read_char(FILE *inf, char *c) { rs_read(inf, c, 1); @@ -505,7 +505,7 @@ } int -rs_read_boolean(int inf, bool *i) +rs_read_boolean(FILE *inf, bool *i) { unsigned char buf; @@ -517,7 +517,7 @@ } int -rs_read_booleans(int inf, bool *i, int count) +rs_read_booleans(FILE *inf, bool *i, int count) { int n = 0, value = 0; @@ -539,7 +539,7 @@ } int -rs_read_shint(int inf, unsigned char *i) +rs_read_shint(FILE *inf, unsigned char *i) { unsigned char buf; @@ -551,7 +551,7 @@ } int -rs_read_short(int inf, short *i) +rs_read_short(FILE *inf, short *i) { unsigned char bytes[2]; short input; @@ -572,7 +572,7 @@ } int -rs_read_shorts(int inf, short *i, int count) +rs_read_shorts(FILE *inf, short *i, int count) { int n = 0, value = 0; @@ -591,7 +591,7 @@ } int -rs_read_ushort(int inf, unsigned short *i) +rs_read_ushort(FILE *inf, unsigned short *i) { unsigned char bytes[2]; unsigned short input; @@ -612,7 +612,7 @@ } int -rs_read_int(int inf, int *i) +rs_read_int(FILE *inf, int *i) { unsigned char bytes[4]; int input; @@ -635,7 +635,7 @@ } int -rs_read_ints(int inf, int *i, int count) +rs_read_ints(FILE *inf, int *i, int count) { int n = 0, value = 0; @@ -654,7 +654,7 @@ } int -rs_read_uint(int inf, unsigned int *i) +rs_read_uint(FILE *inf, unsigned int *i) { unsigned char bytes[4]; int input; @@ -677,7 +677,7 @@ } int -rs_read_long(int inf, long *i) +rs_read_long(FILE *inf, long *i) { unsigned char bytes[4]; long input; @@ -700,7 +700,7 @@ } int -rs_read_longs(int inf, long *i, int count) +rs_read_longs(FILE *inf, long *i, int count) { int n = 0, value = 0; @@ -719,7 +719,7 @@ } int -rs_read_ulong(int inf, unsigned long *i) +rs_read_ulong(FILE *inf, unsigned long *i) { unsigned char bytes[4]; unsigned long input; @@ -742,7 +742,7 @@ } int -rs_read_ulongs(int inf, unsigned long *i, int count) +rs_read_ulongs(FILE *inf, unsigned long *i, int count) { int n = 0, value = 0; @@ -761,7 +761,7 @@ } int -rs_read_string(int inf, char *s, int max) +rs_read_string(FILE *inf, char *s, int max) { int len = 0; @@ -781,7 +781,7 @@ } int -rs_read_new_string(int inf, char **s) +rs_read_new_string(FILE *inf, char **s) { int len=0; char *buf=0; @@ -808,7 +808,7 @@ } int -rs_read_string_index(int inf, char *master[], int maxindex, char **str) +rs_read_string_index(FILE *inf, char *master[], int maxindex, char **str) { int i; @@ -830,7 +830,7 @@ } int -rs_read_strings(int inf, char **s, int count, int max) +rs_read_strings(FILE *inf, char **s, int count, int max) { int len = 0; int n = 0; @@ -858,7 +858,7 @@ } int -rs_read_new_strings(int inf, char **s, int count) +rs_read_new_strings(FILE *inf, char **s, int count) { int len = 0; int n = 0; @@ -903,7 +903,7 @@ } int -rs_read_coord(int inf, struct coord *c) +rs_read_coord(FILE *inf, struct coord *c) { rs_read_int(inf,&c->x); rs_read_int(inf,&c->y); @@ -930,7 +930,7 @@ } int -rs_read_window(int inf, WINDOW *win) +rs_read_window(FILE *inf, WINDOW *win) { int id,row,col,maxlines,maxcols,value,width,height; @@ -1024,7 +1024,7 @@ } int -rs_read_daemons(int inf, struct delayed_action *d_list, int count) +rs_read_daemons(FILE *inf, struct delayed_action *d_list, int count) { int i = 0; int func = 0; @@ -1130,7 +1130,7 @@ } int -rs_read_room_reference(int inf, struct room **rp) +rs_read_room_reference(FILE *inf, struct room **rp) { int i; @@ -1173,7 +1173,7 @@ } int -rs_read_rooms(int inf, struct room *r, int count) +rs_read_rooms(FILE *inf, struct room *r, int count) { int value = 0, n = 0; @@ -1220,7 +1220,7 @@ } int -rs_read_monlev(int inf, struct monlev *m) +rs_read_monlev(FILE *inf, struct monlev *m) { rs_read_int(inf, &m->l_lev); rs_read_int(inf, &m->h_lev); @@ -1247,7 +1247,7 @@ } int -rs_read_magic_items(int inf, struct magic_item *mi, int count) +rs_read_magic_items(FILE *inf, struct magic_item *mi, int count) { int id; int n; @@ -1297,7 +1297,7 @@ } int -rs_read_real(int inf, struct real *r) +rs_read_real(FILE *inf, struct real *r) { rs_read_int(inf,&r->a_str); rs_read_int(inf,&r->a_dex); @@ -1326,7 +1326,7 @@ } int -rs_read_stats(int inf, struct stats *s) +rs_read_stats(FILE *inf, struct stats *s) { int id; @@ -1362,7 +1362,7 @@ } int -rs_read_monster_reference(int inf, struct monster **mp) +rs_read_monster_reference(FILE *inf, struct monster **mp) { int i; @@ -1388,7 +1388,7 @@ } int -rs_read_monster_references(int inf, struct monster *marray[], int count) +rs_read_monster_references(FILE *inf, struct monster *marray[], int count) { int i; @@ -1442,7 +1442,7 @@ } int -rs_read_object(int inf, struct object *o) +rs_read_object(FILE *inf, struct object *o) { int id; @@ -1498,7 +1498,7 @@ } int -rs_read_object_list(int inf, struct linked_list **list) +rs_read_object_list(FILE *inf, struct linked_list **list) { int id; int i, cnt; @@ -1570,7 +1570,7 @@ } int -rs_read_traps(int inf, struct trap *trap, int count) +rs_read_traps(FILE *inf, struct trap *trap, int count) { int id = 0, value = 0, n = 0; @@ -1628,7 +1628,7 @@ } int -rs_read_monsters(int inf, struct monster *m, int count) +rs_read_monsters(FILE *inf, struct monster *m, int count) { int id = 0, value = 0, n = 0; @@ -1813,7 +1813,7 @@ } int -rs_read_thing(int inf, struct thing *t) +rs_read_thing(FILE *inf, struct thing *t) { int id; int listid = 0, index = -1; @@ -1931,7 +1931,7 @@ } int -rs_read_monster_list(int inf, struct linked_list **list) +rs_read_monster_list(FILE *inf, struct linked_list **list) { int id; int i, cnt; @@ -1985,7 +1985,7 @@ } int -rs_read_object_reference(int inf, struct linked_list *list, +rs_read_object_reference(FILE *inf, struct linked_list *list, struct object **item) { int i; @@ -1999,7 +1999,7 @@ int -rs_read_scrolls(int inf) +rs_read_scrolls(FILE *inf) { int i; @@ -2028,7 +2028,7 @@ } int -rs_read_potions(int inf) +rs_read_potions(FILE *inf) { int i; @@ -2058,7 +2058,7 @@ } int -rs_read_rings(int inf) +rs_read_rings(FILE *inf) { int i; @@ -2114,7 +2114,7 @@ } int -rs_read_sticks(int inf) +rs_read_sticks(FILE *inf) { int i = 0, list = 0; @@ -2241,7 +2241,7 @@ } int -rs_restore_file(int inf) +rs_restore_file(FILE *inf) { bool junk; int endian = 0x01020304;