diff options
author | Harald Welte <laforge@gnumonks.org> | 2019-03-18 18:38:47 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-04-10 22:42:32 +0000 |
commit | 179f35702ece13f4ab7fd1b331bef664834d8473 (patch) | |
tree | 9dad4da8eb773040ea8a2dc096190118f5d2abd6 /src/gsm/apn.c | |
parent | d08e9866a5c3da6edda574bbe6d277047d10fded (diff) |
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
Diffstat (limited to 'src/gsm/apn.c')
-rw-r--r-- | src/gsm/apn.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gsm/apn.c b/src/gsm/apn.c index 4ab370c5..88b45a4b 100644 --- a/src/gsm/apn.c +++ b/src/gsm/apn.c @@ -24,6 +24,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <talloc.h> #include <osmocom/gsm/apn.h> @@ -45,6 +46,13 @@ char *osmo_apn_qualify(unsigned int mcc, unsigned int mnc, const char *ni) return osmo_apn_qualify_buf(apn_strbuf, sizeof(apn_strbuf), mcc, mnc, ni); } +char *osmo_apn_qualify_c(const void *ctx, unsigned int mcc, unsigned int mnc, const char *ni) +{ + char *buf = talloc_size(ctx, APN_MAXLEN); + if (!buf) + return NULL; + return osmo_apn_qualify_buf(buf, APN_MAXLEN, mcc, mnc, ni); +} char *osmo_apn_qualify_from_imsi_buf(char *buf, size_t buf_len, const char *imsi, const char *ni, int have_3dig_mnc) @@ -70,6 +78,14 @@ char *osmo_apn_qualify_from_imsi(const char *imsi, return osmo_apn_qualify_from_imsi_buf(apn_strbuf, sizeof(apn_strbuf), imsi, ni, have_3dig_mnc); } +char *osmo_apn_qualify_from_imsi_c(const void *ctx, const char *imsi, const char *ni, int have_3dig_mnc) +{ + char *buf = talloc_size(ctx, APN_MAXLEN); + if (!buf) + return NULL; + return osmo_apn_qualify_from_imsi_buf(buf, APN_MAXLEN, imsi, ni, have_3dig_mnc); +} + /** * Convert an encoded APN into a dot-separated string. * |