laforge submitted this change.
add osmo_scu_prim_name_c() / _buf()
Add non-legacy string functions for osmo_scu_prim_name in the form of
_buf() and _c() signatures.
So far there is only osmo_scu_prim_name() using a static buffer.
Implement that using osmo_scu_prim_name_buf().
Change-Id: I4c1998fd7fee7282d107846dae2cff4b5ceb3a7b
---
M include/osmocom/sigtran/sccp_sap.h
M src/sccp_sap.c
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h
index 5624d33..3930111 100644
--- a/include/osmocom/sigtran/sccp_sap.h
+++ b/include/osmocom/sigtran/sccp_sap.h
@@ -274,6 +274,8 @@
#define msgb_scu_prim(msg) ((struct osmo_scu_prim *)(msg)->l1h)
char *osmo_scu_prim_name(const struct osmo_prim_hdr *oph);
+int osmo_scu_prim_name_buf(char *buf, size_t buflen, const struct osmo_prim_hdr *oph);
+char *osmo_scu_prim_name_c(void *ctx, const struct osmo_prim_hdr *oph);
struct osmo_ss7_instance;
struct osmo_sccp_instance;
diff --git a/src/sccp_sap.c b/src/sccp_sap.c
index cdf0acc..c0a42c6 100644
--- a/src/sccp_sap.c
+++ b/src/sccp_sap.c
@@ -45,14 +45,29 @@
char *osmo_scu_prim_name(const struct osmo_prim_hdr *oph)
{
- const char *name = get_value_string(osmo_scu_prim_names, oph->primitive);
-
- snprintf(prim_name_buf, sizeof(prim_name_buf), "%s.%s", name,
- get_value_string(osmo_prim_op_names, oph->operation));
-
+ osmo_scu_prim_name_buf(prim_name_buf, sizeof(prim_name_buf), oph);
return prim_name_buf;
}
+int osmo_scu_prim_name_buf(char *buf, size_t buflen, const struct osmo_prim_hdr *oph)
+{
+ struct osmo_strbuf sb = { .buf = buf, .len = buflen };
+
+ if (!oph) {
+ OSMO_STRBUF_PRINTF(sb, "null");
+ return sb.chars_needed;
+ }
+
+ OSMO_STRBUF_PRINTF(sb, "%s.%s",
+ get_value_string(osmo_scu_prim_names, oph->primitive),
+ get_value_string(osmo_prim_op_names, oph->operation));
+ return sb.chars_needed;
+}
+
+char *osmo_scu_prim_name_c(void *ctx, const struct osmo_prim_hdr *oph)
+{
+ OSMO_NAME_C_IMPL(ctx, 32, "ERROR", osmo_scu_prim_name_buf, oph)
+}
#include <osmocom/sigtran/sigtran_sap.h>
To view, visit change 31364. To unsubscribe, or for help writing mail filters, visit settings.