diff arogue7/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/arogue7/state.c	Sun Sep 10 17:30:13 2017 -0400
+++ b/arogue7/state.c	Fri Sep 15 19:57:54 2017 -0400
@@ -75,9 +75,9 @@
 
 int list_size(struct linked_list *l);
 int rs_write_int(FILE *savef, int c);
-int rs_read_int(int inf, int *i);
+int rs_read_int(FILE *inf, int *i);
 int rs_write_object_list(FILE *savef, struct linked_list *l);
-int rs_read_object_list(int inf, struct linked_list **list);
+int rs_read_object_list(FILE *inf, struct linked_list **list);
 
 int
 rs_write(FILE *savef, void *ptr, size_t size)
@@ -85,14 +85,14 @@
     if (write_error)
         return(WRITESTAT);
 
-    if (encwrite(ptr, size, md_fileno(savef)) != size)
+    if (encwrite(ptr, size, savef) != size)
         write_error = 1;
 
     return(WRITESTAT);
 }
 
 int
-rs_read(int inf, void *ptr, size_t size)
+rs_read(FILE *inf, void *ptr, size_t size)
 {
     if (read_error || format_error)
         return(READSTAT);
@@ -115,7 +115,7 @@
 }
 
 int
-rs_read_uchar(int inf, unsigned char *c)
+rs_read_uchar(FILE *inf, unsigned char *c)
 {
     if (read_error || format_error)
         return(READSTAT);
@@ -137,7 +137,7 @@
 }
 
 int
-rs_read_char(int inf, char *c)
+rs_read_char(FILE *inf, char *c)
 {
     if (read_error || format_error)
         return(READSTAT);
@@ -160,7 +160,7 @@
 }
 
 int
-rs_read_chars(int inf, char *i, int count)
+rs_read_chars(FILE *inf, char *i, int count)
 {
     int value = 0;
     
@@ -201,7 +201,7 @@
 }
 
 int
-rs_read_int(int inf, int *i)
+rs_read_int(FILE *inf, int *i)
 {
     unsigned char bytes[4];
     int input = 0;
@@ -244,7 +244,7 @@
 }
 
 int
-rs_read_ints(int inf, int *i, int count)
+rs_read_ints(FILE *inf, int *i, int count)
 {
     int n, value;
     
@@ -277,7 +277,7 @@
 }
 
 int
-rs_read_boolean(int inf, bool *i)
+rs_read_boolean(FILE *inf, bool *i)
 {
     unsigned char buf = 0;
     
@@ -309,7 +309,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;
     
@@ -350,7 +350,7 @@
 }
 
 int
-rs_read_short(int inf, short *i)
+rs_read_short(FILE *inf, short *i)
 {
     unsigned char bytes[2];
     short  input;
@@ -391,7 +391,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;
 
@@ -432,7 +432,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;
@@ -479,7 +479,7 @@
 }
 
 int
-rs_read_uint(int inf, unsigned int *i)
+rs_read_uint(FILE *inf, unsigned int *i)
 {
     unsigned char bytes[4];
     int  input;
@@ -535,7 +535,7 @@
 }
 
 int
-rs_read_long(int inf, long *i)
+rs_read_long(FILE *inf, long *i)
 {
     unsigned char bytes[4];
     long input;
@@ -580,7 +580,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;
     
@@ -630,7 +630,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;
@@ -676,7 +676,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;
     
@@ -707,7 +707,7 @@
 }
 
 int 
-rs_read_marker(int inf, int id)
+rs_read_marker(FILE *inf, int id)
 {
     int nid;
 
@@ -742,7 +742,7 @@
 }
 
 int
-rs_read_string(int inf, char *s, int max)
+rs_read_string(FILE *inf, char *s, int max)
 {
     int len = 0;
 
@@ -760,7 +760,7 @@
 }
 
 int
-rs_read_new_string(int inf, char **s)
+rs_read_new_string(FILE *inf, char **s)
 {
     int len=0;
     char *buf=0;
@@ -805,7 +805,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 n     = 0;
     int value = 0;
@@ -826,7 +826,7 @@
 }
 
 int
-rs_read_new_strings(int inf, char **s, int count)
+rs_read_new_strings(FILE *inf, char **s, int count)
 {
     int n     = 0;
     int value = 0;
@@ -862,7 +862,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;
 
@@ -894,7 +894,7 @@
 }
 
 int
-rs_read_coord(int inf, coord *c)
+rs_read_coord(FILE *inf, coord *c)
 {
     coord in;
 
@@ -929,7 +929,7 @@
 }
 
 int
-rs_read_coord_list(int inf, struct linked_list **list)
+rs_read_coord_list(FILE *inf, struct linked_list **list)
 {
     int i, cnt;
     struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@@ -987,7 +987,7 @@
 }
 
 int
-rs_read_window(int inf, WINDOW *win)
+rs_read_window(FILE *inf, WINDOW *win)
 {
     int row,col,maxlines,maxcols,value,width,height;
     
@@ -1075,7 +1075,7 @@
 }
 
 int
-rs_read_levtype(int inf, LEVTYPE *l)
+rs_read_levtype(FILE *inf, LEVTYPE *l)
 {
     int lt;
     
@@ -1120,7 +1120,7 @@
 }
 
 int
-rs_read_stats(int inf, struct stats *s)
+rs_read_stats(FILE *inf, struct stats *s)
 {
     if (read_error || format_error)
         return(READSTAT);
@@ -1165,7 +1165,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 n;
     int value;
@@ -1210,7 +1210,7 @@
 }
 
 int
-rs_read_scrolls(int inf)
+rs_read_scrolls(FILE *inf)
 {
     int i;
 
@@ -1246,7 +1246,7 @@
 }
 
 int
-rs_read_potions(int inf)
+rs_read_potions(FILE *inf)
 {
     int i;
 
@@ -1282,7 +1282,7 @@
 }
 
 int
-rs_read_rings(int inf)
+rs_read_rings(FILE *inf)
 {
     int i;
 
@@ -1317,7 +1317,7 @@
 }
 
 int
-rs_read_misc(int inf)
+rs_read_misc(FILE *inf)
 {
     int i;
 
@@ -1364,7 +1364,7 @@
 }
         
 int
-rs_read_sticks(int inf)
+rs_read_sticks(FILE *inf)
 {
     int i = 0, j = 0, list = 0;
 
@@ -1588,7 +1588,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;
@@ -1774,7 +1774,7 @@
 }
 
 int
-rs_read_room(int inf, struct room *r)
+rs_read_room(FILE *inf, struct room *r)
 {
     int value = 0, n = 0, i = 0, index = 0, id = 0;
     struct linked_list *fires=NULL, *item = NULL;
@@ -1831,7 +1831,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;
 
@@ -1867,7 +1867,7 @@
 }
 
 int
-rs_read_room_reference(int inf, struct room **rp)
+rs_read_room_reference(FILE *inf, struct room **rp)
 {
     int i;
     
@@ -1911,7 +1911,7 @@
 }
 
 int
-rs_read_door_reference(int inf, coord **exit)
+rs_read_door_reference(FILE *inf, coord **exit)
 {
     int i, idx;
 
@@ -1945,7 +1945,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;
 
@@ -1992,7 +1992,7 @@
 }
 
 int
-rs_read_monsters(int inf, struct monster *m, int count)
+rs_read_monsters(FILE *inf, struct monster *m, int count)
 {
     int value = 0, n = 0;
 
@@ -2044,7 +2044,7 @@
 }
 
 int
-rs_read_object(int inf, struct object *o)
+rs_read_object(FILE *inf, struct object *o)
 {
     if (read_error || format_error)
         return(READSTAT);
@@ -2085,7 +2085,7 @@
 }
 
 int
-rs_read_object_list(int inf, struct linked_list **list)
+rs_read_object_list(FILE *inf, struct linked_list **list)
 {
     int i, cnt;
     struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@@ -2137,7 +2137,7 @@
 }
 
 int
-rs_read_object_reference(int inf, struct linked_list *list, struct object **item)
+rs_read_object_reference(FILE *inf, struct linked_list *list, struct object **item)
 {
     int i;
     
@@ -2280,7 +2280,7 @@
 }
 
 int
-rs_read_thing(int inf, struct thing *t)
+rs_read_thing(FILE *inf, struct thing *t)
 {
     int listid = 0, index = -1;
 
@@ -2395,7 +2395,7 @@
 }
 
 int
-rs_read_thing_list(int inf, struct linked_list **list)
+rs_read_thing_list(FILE *inf, struct linked_list **list)
 {
     int i, cnt;
     struct linked_list *l = NULL, *previous = NULL, *head = NULL;
@@ -2462,7 +2462,7 @@
 }
 
 int
-rs_read_thing_reference(int inf, struct linked_list *list, struct thing **item)
+rs_read_thing_reference(FILE *inf, struct linked_list *list, struct thing **item)
 {
     int i;
     
@@ -2494,7 +2494,7 @@
 }
 
 int
-rs_read_thing_references(int inf, struct linked_list *list, struct thing *items[], int count)
+rs_read_thing_references(FILE *inf, struct linked_list *list, struct thing *items[], int count)
 {
     int i;
 
@@ -2635,7 +2635,7 @@
 }
 
 int
-rs_restore_file(int inf)
+rs_restore_file(FILE *inf)
 {
     int i;