summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-10-20 20:37:20 +0100
committerLars Wirzenius <liw@liw.fi>2010-10-20 20:37:20 +0100
commite471d201ee5b2423eb6cb4855b7b7c8ff0483119 (patch)
tree03bf7157a19ed18ee465c2b310bb566ab1a12fc4
parentbb7232044cfc09a51b899ab73d9df6d076d130fc (diff)
downloaddynstr-e471d201ee5b2423eb6cb4855b7b7c8ff0483119.tar.gz
Implement dynstr_set_malloc_error_handler.
-rw-r--r--dynstr.c9
-rw-r--r--unittests.c10
2 files changed, 19 insertions, 0 deletions
diff --git a/dynstr.c b/dynstr.c
index 41cb6ef..28804bf 100644
--- a/dynstr.c
+++ b/dynstr.c
@@ -23,6 +23,15 @@ dynstr_error_handler *dynstr_get_malloc_error_handler(void)
return error_handler;
}
+void dynstr_set_malloc_error_handler(dynstr_error_handler *handler)
+{
+ error_handler = handler;
+}
+
void dynstr_malloc_error_indicate(int error, size_t size, void *oldptr)
{
}
+
+void dynstr_malloc_error_abort(int error, size_t size, void *oldptr)
+{
+}
diff --git a/unittests.c b/unittests.c
index 0f43982..fd30081 100644
--- a/unittests.c
+++ b/unittests.c
@@ -22,6 +22,15 @@ static int test_default_error_handler_is_indicate(void)
}
+static int test_sets_error_handler(void)
+{
+ dynstr_set_malloc_error_handler(dynstr_malloc_error_abort);
+ FAIL_UNLESS_EQUAL(dynstr_get_malloc_error_handler(),
+ dynstr_malloc_error_abort);
+ return true;
+}
+
+
struct test {
const char *name;
int (*test)(void);
@@ -32,6 +41,7 @@ struct test {
static const struct test tests[] = {
TEST(test_default_error_handler_is_indicate),
+ TEST(test_sets_error_handler),
};
static const int num_tests = sizeof(tests) / sizeof(tests[0]);