home · contact · privacy
Don't use ncurses windows besides the virtual screen pad. Eliminated some ncurses...
[plomrogue] / src / readwrite.c
index 4b2f2a6af37628511c2e1dcc5fbc5327a06d9a68..657d8173dd674ecfa9528cfce9653ee5dd841449 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "readwrite.h"
 #include <stdio.h>  /* for FILE typedef, fopen(), fgetc(), fputc(), fseek(),
-                     * sprintf()
+                     * sprintf(), fwrite(), ferror()
                      */
 #include <stdint.h> /* for uint8_t, uint16_t, uint32_t */
 #include <string.h> /* for strlen()*/
@@ -59,11 +59,23 @@ extern void try_fclose(FILE * file, struct World * w, char * f)
 
 
 
-extern void try_fgets(char * line, int linemax, FILE * file,
-                      struct World * w, char * f)
+extern char * try_fgets(char * line, int linemax, FILE * file,
+                        struct World * w, char * f)
 {
     char * msg = trouble_msg(w, f, "fgets()");
-    exit_err(NULL == fgets(line, linemax, file), w, msg);
+    char * test = fgets(line, linemax, file);
+    exit_err(NULL == test && ferror(file), w, msg);
+    free(msg);
+    return test;
+}
+
+
+
+extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream,
+                       struct World * w, char * f)
+{
+    char * msg = trouble_msg(w, f, "fwrite()");
+    exit_err(0 == fwrite(ptr, size, nmemb, stream), w, msg);
     free(msg);
 }