This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/24598 ) Change subject: utils: introduce osmo_talloc_replace_string_fmt() ...................................................................... utils: introduce osmo_talloc_replace_string_fmt() Change-Id: I6b84fa0525555a98c531fc558e5dc1298fec00c1 --- M include/osmocom/core/utils.h M src/utils.c 2 files changed, 23 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 85a8cb3..1fdb0eb 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -117,6 +117,8 @@ *dst = talloc_strdup(ctx, newstr); } +void osmo_talloc_replace_string_fmt(void *ctx, char **dst, const char *fmt, ...); + /*! Append to a string and re-/allocate if necessary. * \param[in] ctx Talloc context to use for initial allocation. * \param[in,out] dest char* to re-/allocate and append to. diff --git a/src/utils.c b/src/utils.c index c180595..626dcb4 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1493,4 +1493,25 @@ return rc; } +/*! Replace a string using talloc and release its prior content (if any). + * This is a format string capable equivalent of osmo_talloc_replace_string(). + * \param[in] ctx Talloc context to use for allocation. + * \param[out] dst Pointer to string, will be updated with ptr to new string. + * \param[in] fmt Format string that will be copied to newly allocated string. */ +void osmo_talloc_replace_string_fmt(void *ctx, char **dst, const char *fmt, ...) +{ + char *name = NULL; + + if (fmt != NULL) { + va_list ap; + + va_start(ap, fmt); + name = talloc_vasprintf(ctx, fmt, ap); + va_end(ap); + } + + talloc_free(*dst); + *dst = name; +} + /*! @} */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24598 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I6b84fa0525555a98c531fc558e5dc1298fec00c1 Gerrit-Change-Number: 24598 Gerrit-PatchSet: 2 Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier at sysmocom.de> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211013/3cde5a85/attachment.htm>