From 179f35702ece13f4ab7fd1b331bef664834d8473 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 18 Mar 2019 18:38:47 +0100 Subject: Add _c versions of functions that otherwise return static buffers We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b --- src/gb/gprs_ns.c | 8 ++++++++ src/gb/libosmogb.map | 1 + 2 files changed, 9 insertions(+) (limited to 'src/gb') diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index fc120cec..d72003ed 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -1552,6 +1552,14 @@ const char *gprs_ns_ll_str(const struct gprs_nsvc *nsvc) return gprs_ns_ll_str_buf(buf, sizeof(buf), nsvc); } +char *gprs_ns_ll_str_c(const void *ctx, const struct gprs_nsvc *nsvc) +{ + char *buf = talloc_size(ctx, INET6_ADDRSTRLEN+10); + if (!buf) + return buf; + return gprs_ns_ll_str_buf(buf, INET6_ADDRSTRLEN+10, nsvc); +} + void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other) { nsvc->ll = other->ll; diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map index 21929da1..5e675a66 100644 --- a/src/gb/libosmogb.map +++ b/src/gb/libosmogb.map @@ -65,6 +65,7 @@ gprs_ns_tx_unblock; gprs_ns_vty_init; gprs_ns_ll_str; gprs_ns_ll_str_buf; +gprs_ns_ll_str_c; gprs_ns_ll_copy; gprs_ns_ll_clear; gprs_ns_msgb_alloc; -- cgit v1.2.3