summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ckpass.c10
-rw-r--r--src/ckpasswd.c10
-rw-r--r--src/messages.c9
-rw-r--r--src/messages.h18
-rw-r--r--src/xmalloc.c2
-rw-r--r--src/xmalloc.h28
6 files changed, 53 insertions, 24 deletions
diff --git a/src/ckpass.c b/src/ckpass.c
index 1da83c6..9d7e63d 100644
--- a/src/ckpass.c
+++ b/src/ckpass.c
@@ -42,14 +42,8 @@
# define OPT_SHADOW ""
#endif
-/* The functions are actually macros so that we can pick up the file and line
- number information for debugging error messages without the user having to
- pass those in every time. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#include "messages.h"
+#include "xmalloc.h"
#include <security/pam_appl.h>
diff --git a/src/ckpasswd.c b/src/ckpasswd.c
index 9dbdbcf..0ccf986 100644
--- a/src/ckpasswd.c
+++ b/src/ckpasswd.c
@@ -43,14 +43,8 @@
# define OPT_SHADOW ""
#endif
-/* The functions are actually macros so that we can pick up the file and line
- number information for debugging error messages without the user having to
- pass those in every time. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#include "messages.h"
+#include "xmalloc.h"
#include <security/pam_appl.h>
diff --git a/src/messages.c b/src/messages.c
index 7a54e0a..2373fbf 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -82,14 +82,7 @@
#include <pwd.h>
#include <grp.h>
-/* The functions are actually macros so that we can pick up the file and line
- number information for debugging error messages without the user having to
- pass those in every time. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
-#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#include "xmalloc.h"
/* These are the currently-supported types of traces. */
enum message_trace {
diff --git a/src/messages.h b/src/messages.h
new file mode 100644
index 0000000..2133e4b
--- /dev/null
+++ b/src/messages.h
@@ -0,0 +1,18 @@
+/* $Id: messages.h $
+ *
+ * Message and error reporting (possibly fatal).
+ *
+ */
+
+#if !defined(_MESSAGES_H)
+#define _MESSAGES_H
+
+/* The reporting functions. The ones prefaced by "sys" add a colon, a space,
+ and the results of strerror(errno) to the output and are intended for
+ reporting failures of system calls. */
+extern void die(const char *, ...)
+ __attribute__((__noreturn__, __format__(printf, 1, 2)));
+extern void sysdie(const char *, ...)
+ __attribute__((__noreturn__, __format__(printf, 1, 2)));
+
+#endif /* _MESSAGES_H */
diff --git a/src/xmalloc.c b/src/xmalloc.c
index 4d00c52..f72f287 100644
--- a/src/xmalloc.c
+++ b/src/xmalloc.c
@@ -70,6 +70,8 @@
#include <pwd.h>
#include <grp.h>
+#include "messages.h"
+
/* Failure handler takes the function, the size, the file, and the line. */
typedef void (*xmalloc_handler_t)(const char *, size_t, const char *, int);
diff --git a/src/xmalloc.h b/src/xmalloc.h
new file mode 100644
index 0000000..6f64ddc
--- /dev/null
+++ b/src/xmalloc.h
@@ -0,0 +1,28 @@
+/* $Id: xmalloc.h $
+ *
+ * malloc routines with failure handling.
+ *
+ */
+
+#if !defined(_XMALLOC_H)
+#define _XMALLOC_H
+
+/* The functions are actually macros so that we can pick up the file and line
+ number information for debugging error messages without the user having to
+ pass those in every time. */
+#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
+#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
+#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__)
+#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
+#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+
+/*
+ * Prototypes of functions
+ */
+void* x_malloc(size_t size, const char *file, int line);
+void* x_calloc(size_t n, size_t size, const char *file, int line);
+void* x_realloc(void *p, size_t size, const char *file, int line);
+char* x_strdup(const char *s, const char *file, int line);
+char* x_strndup(const char *s, size_t size, const char *file, int line);
+
+#endif /* _XMALLOC_H */