home · contact · privacy
Some code-stylistic improvements to rexit library; also moved exit_trouble() into it.
[plomrogue] / src / misc.c
index e71770daf8361b8a6df34c8b35f27b137596414f..2cf9e62f936671b84faeca3eaecb4df8cb5fd267 100644 (file)
@@ -16,7 +16,7 @@
 #include "map.h" /* for Map struct, is_passable() */
 #include "main.h" /* for world global */
 #include "yx_uint16.h" /* for yx_uint16 struct */
-#include "rexit.h" /* for exit_err() */
+#include "rexit.h" /* for exit_err(), exit_trouble() */
 #include "wincontrol.h" /* for init_winconfs(), init_wins(), free_winconfs(),
                          * sorted_wintoggle_and_activate()
                          */
@@ -34,27 +34,10 @@ extern uint16_t rrand()
 
 
 
-extern char * trouble_msg(char * parent, char * child)
-{
-    char * p1 = "Trouble in ";
-    char * p2 = " with ";
-    char * p3 = ".";
-    uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
-                    + strlen(p3) + 1;
-    char * msg = malloc(size);
-    exit_err(NULL == msg, "malloc() in trouble_msg() failed.");
-    sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
-    return msg;
-}
-
-
-
 extern void * try_malloc(size_t size, char * f)
 {
-    char * msg = trouble_msg(f, "malloc()");
     void * p = malloc(size);
-    exit_err(NULL == p, msg);
-    free(msg);
+    exit_trouble(NULL == p, f, "malloc()");
     return p;
 }
 
@@ -62,10 +45,8 @@ extern void * try_malloc(size_t size, char * f)
 
 extern void * try_calloc(size_t size1, size_t size2, char * f)
 {
-    char * msg = trouble_msg(f, "calloc()");
     void * p = calloc(size1, size2);
-    exit_err(NULL == p, msg);
-    free(msg);
+    exit_trouble(NULL == p, f, "calloc()");
     return p;
 }