home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Server/py: Remove unnecessary libpr restype / argtype settings.
[plomrogue]
/
src
/
common
/
rexit.c
diff --git
a/src/common/rexit.c
b/src/common/rexit.c
index 7b837e946987bc59b658ba441f5129b1c22a1c7a..7eeaccb52d1c92d91a3c9760771888de70b16bde 100644
(file)
--- a/
src/common/rexit.c
+++ b/
src/common/rexit.c
@@
-1,11
+1,17
@@
-/* src/common/rexit.c */
+/* src/common/rexit.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
#include "rexit.h"
#include <errno.h> /* global errno */
#include <stdint.h> /* uint16_t */
#include <stdio.h> /* printf(), perror(), sprintf() */
#include "rexit.h"
#include <errno.h> /* global errno */
#include <stdint.h> /* uint16_t */
#include <stdio.h> /* printf(), perror(), sprintf() */
-#include <stdlib.h> /* exit(), EXIT_FAILURE */
+#include <stdlib.h> /* exit(),
free(),
EXIT_FAILURE */
#include <string.h> /* strlen() */
#include <string.h> /* strlen() */
+#include "try_malloc.h" /* try_malloc() */
@@
-20,20
+26,18
@@
extern void set_cleanup_func(void (* f)())
-extern void exit_err(int err, char * msg)
+extern void exit_err(int err, c
onst c
har * msg)
{
if (0 == err)
{
return;
}
cleanup_func();
{
if (0 == err)
{
return;
}
cleanup_func();
- if (
NULL ==
msg)
+ if (
!
msg)
{
msg = "Details unknown.";
}
{
msg = "Details unknown.";
}
- printf("Aborted program due to error. %s\n"
- "Internal error code: %d\n",
- msg, err);
+ printf("Aborted program due to error. %s\n", msg);
if (0 != errno)
{
perror("errno states");
if (0 != errno)
{
perror("errno states");
@@
-43,14
+47,16
@@
extern void exit_err(int err, char * msg)
-extern void exit_trouble(int err, c
har * parent,
char * child)
+extern void exit_trouble(int err, c
onst char * parent, const
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 * p1 = "Trouble in ";
char * p2 = " with ";
char * p3 = ".";
uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
+ strlen(p3) + 1;
- char msg[size];
- sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ char * msg = try_malloc(size, __func__);
+ int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ exit_err(test < 0, "Trouble in exit_trouble with sprintf.");
exit_err(err, msg);
exit_err(err, msg);
+ free(msg);
}
}