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, 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, char * parent, char * child)
47 char * f_name = "exit_trouble()";
48 char * p1 = "Trouble in ";
51 uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
53 char * msg = try_malloc(size, f_name);
54 int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
55 exit_err(test < 0, "Trouble in exit_trouble() with sprintf()");