+
+
+/* Read/write "x" from/to "file" as bigendian representation of "size" bits. On
+ * failure, return 1, else 0. (As of of now, all extern read/write functions
+ * build on top of these.)
+ *
+ * Only use multiples of 8 greater or equal 32 for "size", so that storage
+ * inside uint32_t is possible. Originally a bit number check prefaced the code
+ * of both functions. It was removed as redundant due to all possible "size"
+ * values being hardcoded into the library (i.e. in all extern functions calling
+ * / wrapping around either function). If this ever changes, (re-)insert:
+ *
+ * if (0 == size || size > 32 || 0 != size % 8)
+ * {
+ * return 1;
+ * }
+ */
+static uint8_t read_uintX_bigendian(FILE * file, uint32_t * x, uint8_t size);
+static uint8_t write_uintX_bigendian(FILE * file, uint32_t x, uint8_t size);
+
+
+
+extern FILE * try_fopen(char * path, char * mode, char * f)
+{
+ char * msg1 = "Trouble in ";
+ char * msg2 = " with fopen() (mode '";
+ char * msg3 = "') on path '";
+ char * msg4 = "'.";
+ uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg3) + strlen(msg4)
+ + strlen(f) + strlen(path) + strlen(mode) + 1;
+ char msg[size];
+ sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, mode, msg3, path, msg4);
+ FILE * file_p = fopen(path, mode);
+ exit_err(NULL == file_p, msg);
+ return file_p;
+}
+
+
+
+extern void try_fclose(FILE * file, char * f)
+{
+ exit_trouble(fclose(file), f, "fclose()");
+}
+
+
+
+extern char * try_fgets(char * line, int linemax, FILE * file, char * f)
+{
+ char * test = fgets(line, linemax, file);
+ exit_trouble(NULL == test && ferror(file), f, "fgets()");
+ return test;
+}
+
+
+
+extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream,
+ char * f)