neels submitted this change.
umts_cell_id: add umts_cell_id_to_str_buf()
Prepare for umts_cell_id_test.c: allow testing the to_str conversion
without using talloc.
Change-Id: I3cc0169593c73c2e658637e4116ddd578f83df6d
---
M include/osmocom/hnbgw/hnbgw.h
M src/osmo-hnbgw/hnbgw.c
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h
index 2c7e014..87844f4 100644
--- a/include/osmocom/hnbgw/hnbgw.h
+++ b/include/osmocom/hnbgw/hnbgw.h
@@ -173,6 +173,8 @@
uint16_t sac; /*!< Service Area Code */
uint32_t cid; /*!< Cell ID */
};
+int umts_cell_id_to_str_buf(char *buf, size_t buflen, const struct umts_cell_id *ucid);
+char *umts_cell_id_to_str_c(void *ctx, const struct umts_cell_id *ucid);
const char *umts_cell_id_to_str(const struct umts_cell_id *ucid);
int umts_cell_id_from_str(struct umts_cell_id *ucid, const char *instr);
uint32_t umts_cell_id_hash(const struct umts_cell_id *ucid);
diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c
index c41fb54..4f3fafa 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -232,15 +232,24 @@
return ctx;
}
-const char *umts_cell_id_to_str(const struct umts_cell_id *ucid)
+int umts_cell_id_to_str_buf(char *buf, size_t buflen, const struct umts_cell_id *ucid)
{
const char *fmtstr = "%03u-%02u-L%u-R%u-S%u-C%u";
if (g_hnbgw->config.plmn.mnc_3_digits)
fmtstr = "%03u-%03u-L%u-R%u-S%u-C%u";
+ return snprintf(buf, buflen, fmtstr, ucid->mcc, ucid->mnc, ucid->lac, ucid->rac,
+ ucid->sac, ucid->cid);
+}
- return talloc_asprintf(OTC_SELECT, fmtstr, ucid->mcc, ucid->mnc, ucid->lac, ucid->rac,
- ucid->sac, ucid->cid);
+char *umts_cell_id_to_str_c(void *ctx, const struct umts_cell_id *ucid)
+{
+ OSMO_NAME_C_IMPL(ctx, 64, "ERROR", umts_cell_id_to_str_buf, ucid)
+}
+
+const char *umts_cell_id_to_str(const struct umts_cell_id *ucid)
+{
+ return umts_cell_id_to_str_c(OTC_SELECT, ucid);
}
/* Useful to index a hash table by struct umts_cell_id. */
To view, visit change 36891. To unsubscribe, or for help writing mail filters, visit settings.