1 /* src/common/rexit.c */
4 #include <errno.h> /* global errno */
5 #include <stdint.h> /* uint16_t */
6 #include <stdio.h> /* printf(), perror(), sprintf() */
7 #include <stdlib.h> /* exit(), free(), EXIT_FAILURE */
8 #include <string.h> /* strlen() */
9 #include "try_malloc.h" /* try_malloc() */
13 void (* cleanup_func) ();
17 extern void set_cleanup_func(void (* f)())
24 extern void exit_err(int err, const char * msg)
33 msg = "Details unknown.";
35 printf("Aborted program due to error. %s\n", msg);
38 perror("errno states");
45 extern void exit_trouble(int err, const char * parent, const char * child)
47 char * p1 = "Trouble in ";
50 uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
52 char * msg = try_malloc(size, __func__);
53 int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
54 exit_err(test < 0, "Trouble in exit_trouble with sprintf.");