pespin submitted this change.

View Change

Approvals: Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve osmith: Looks good to me, approved
osmo_io: Introduce API osmo_iofd_set_name_f()

Change-Id: I0800255fde37d4b3c096c4a4a53e370c546c1f16
---
M TODO-RELEASE
M include/osmocom/core/osmo_io.h
M src/core/libosmocore.map
M src/core/osmo_io.c
4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/TODO-RELEASE b/TODO-RELEASE
index 4859444..3c98f06 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -9,3 +9,4 @@
#library what description / commit summary line
core added osmo_sock_set_nonblock(), osmo_sock_get_nonblock()
core added gsmtap_source_set_nonblock(), gsmtap_source_using_wq()
+core added osmo_iofd_set_name_f()
diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h
index 0733240..c428191 100644
--- a/include/osmocom/core/osmo_io.h
+++ b/include/osmocom/core/osmo_io.h
@@ -240,6 +240,7 @@
int osmo_iofd_get_fd(const struct osmo_io_fd *iofd);
const char *osmo_iofd_get_name(const struct osmo_io_fd *iofd);
void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name);
+void osmo_iofd_set_name_f(struct osmo_io_fd *iofd, const char *fmt, ...);

int osmo_iofd_set_ioops(struct osmo_io_fd *iofd, const struct osmo_io_ops *ioops);
void osmo_iofd_get_ioops(struct osmo_io_fd *iofd, struct osmo_io_ops *ioops);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index 6a46f6c..2818f8a 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -267,6 +267,7 @@
osmo_iofd_get_fd;
osmo_iofd_get_name;
osmo_iofd_set_name;
+osmo_iofd_set_name_f;
osmo_iofd_get_priv_nr;
osmo_iofd_init;
osmo_iofd_mode_names;
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index b28f170..1a55ff1 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -1153,6 +1153,24 @@
osmo_talloc_replace_string(iofd, &iofd->name, name);
}

+/*! Set the human-readable name of the file descriptor using arguments like printf()
+ * \param[in] iofd the file descriptor
+ * \param[in] fmt the fmt to set on the file descriptor */
+void osmo_iofd_set_name_f(struct osmo_io_fd *iofd, const char *fmt, ...)
+{
+ char *name = NULL;
+
+ if (fmt) {
+ va_list ap;
+
+ va_start(ap, fmt);
+ name = talloc_vasprintf(iofd, fmt, ap);
+ va_end(ap);
+ }
+ talloc_free((void *)iofd->name);
+ iofd->name = name;
+}
+
/*! Set the osmo_io_ops calbacks for an osmo_io_fd.
* This function can be used to update/overwrite the call-back functions for the given osmo_io_fd; it
* replaces the currently-set call-back function pointers from a previous call to osmo_iofd_set_ioops()

To view, visit change 41853. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0800255fde37d4b3c096c4a4a53e370c546c1f16
Gerrit-Change-Number: 41853
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: jolly <andreas@eversberg.eu>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>