From a2d52669aa19f2e3e07d445f8421945d3855b085 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Apr 2020 10:44:42 +0200 Subject: [PATCH] shared/strbuf: add nm_str_buf_ensure_trailing_c() helper function --- shared/nm-glib-aux/nm-str-buf.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shared/nm-glib-aux/nm-str-buf.h b/shared/nm-glib-aux/nm-str-buf.h index 564f91c4b5..5701fcdee2 100644 --- a/shared/nm-glib-aux/nm-str-buf.h +++ b/shared/nm-glib-aux/nm-str-buf.h @@ -129,6 +129,16 @@ void nm_str_buf_append_printf (NMStrBuf *strbuf, const char *format, ...) _nm_printf (2, 3); +static inline void +nm_str_buf_ensure_trailing_c (NMStrBuf *strbuf, char ch) +{ + _nm_str_buf_assert (strbuf); + + if ( strbuf->len == 0 + || strbuf->_str[strbuf->len - 1] != ch) + nm_str_buf_append_c (strbuf, ch); +} + /*****************************************************************************/ /**