From 4d68fd0955010625cbaa7d19cb9f69b9f44900ab Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 5 Mar 2018 04:16:48 +0100 Subject: [PATCH] gsm23003: add osmo_mcc_from_str() I found myself often using osmo_mnc_from_str() to also decode an MCC and be strict about it, but each time I felt the need to comment like "using osmo_mnc_from_str() also for MCC". Rather formalize this properly. Use a static inline function, no need to add more symbols to libosmo-gsm. Change-Id: I020a4f11791c61742a3d795f782805f7b7e8733e --- include/osmocom/gsm/gsm23003.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/osmocom/gsm/gsm23003.h b/include/osmocom/gsm/gsm23003.h index 660186e3b..5d1fbd7fd 100644 --- a/include/osmocom/gsm/gsm23003.h +++ b/include/osmocom/gsm/gsm23003.h @@ -98,5 +98,16 @@ void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn); int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits); +/* Convert string to MCC. + * \param mcc_str[in] String representation of an MCC, with or without leading zeros. + * \param mcc[out] MCC result buffer, or NULL. + * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion + * errors. In case of error, do not modify the out-arguments. + */ +static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc) +{ + return osmo_mnc_from_str(mcc_str, mcc, NULL); +} + int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits); int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);