summaryrefslogtreecommitdiffstats
path: root/src/fastd.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
commit546ac7936340312cf272969ff83317ae4d50d2b4 (patch)
tree7ecadca11430c8624d9f80aae7c348fa4d65b969 /src/fastd.h
parentb22364f4af3564f0dd9a5f4e150bb09747bd5c4e (diff)
downloadfastd-546ac7936340312cf272969ff83317ae4d50d2b4.tar
fastd-546ac7936340312cf272969ff83317ae4d50d2b4.zip
Introduce and use alloc helpers
These new helpers will terminate fastd on allocation failures and add some additional convenience (allow strdup with NULL; typesafe new(type) macros).
Diffstat (limited to 'src/fastd.h')
-rw-r--r--src/fastd.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/fastd.h b/src/fastd.h
index 8700be2..5619e66 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -32,7 +32,7 @@
#pragma once
-#include "types.h"
+#include "alloc.h"
#include "dlist.h"
#include "buffer.h"
#include "log.h"
@@ -395,7 +395,7 @@ static inline bool fastd_peer_address_is_v6_ll(const fastd_peer_address_t *addr)
/** Duplicates a string, creating a one-element string stack */
static inline fastd_string_stack_t* fastd_string_stack_dup(const char *str) {
- fastd_string_stack_t *ret = malloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8));
+ fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8));
ret->next = NULL;
strcpy(ret->str, str);
@@ -405,7 +405,7 @@ static inline fastd_string_stack_t* fastd_string_stack_dup(const char *str) {
/** Duplicates a string of a given maximum length, creating a one-element string stack */
static inline fastd_string_stack_t* fastd_string_stack_dupn(const char *str, size_t len) {
size_t str_len = strnlen(str, len);
- fastd_string_stack_t *ret = malloc(alignto(sizeof(fastd_string_stack_t) + str_len + 1, 8));
+ fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + str_len + 1, 8));
ret->next = NULL;
strncpy(ret->str, str, str_len);
ret->str[str_len] = 0;
@@ -415,7 +415,7 @@ static inline fastd_string_stack_t* fastd_string_stack_dupn(const char *str, siz
/** Pushes the copy of a string onto the top of a string stack */
static inline fastd_string_stack_t* fastd_string_stack_push(fastd_string_stack_t *stack, const char *str) {
- fastd_string_stack_t *ret = malloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8));
+ fastd_string_stack_t *ret = fastd_alloc(alignto(sizeof(fastd_string_stack_t) + strlen(str) + 1, 8));
ret->next = stack;
strcpy(ret->str, str);