chiark / gitweb /
util: priomsg: Provide and use priomsg_update_fixed
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Sep 2019 15:40:15 +0000 (16:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:17 +0000 (19:16 +0100)
We are going to want to reuse this.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
site.c
util.c
util.h

diff --git a/site.c b/site.c
index 8ca87690baf350f7c3fee99ddd595db34bb4ade8..57ccb1dcdc4d0811a136c78a0cc229aa1ecd4778 100644 (file)
--- a/site.c
+++ b/site.c
@@ -2084,9 +2084,8 @@ static bool_t site_incoming(void *sst, struct buffer_if *buf,
        return True;
     }
 
-    if (priomsg_update_p(whynot, comm_notify_whynot_general))
-       truncmsg_add_string(&whynot->m,
-                           "not MSG1 or PROD; unknown dest index");
+    priomsg_update_fixed(whynot, comm_notify_whynot_general,
+                        "not MSG1 or PROD; unknown dest index");
     return False;
 }
 
diff --git a/util.c b/util.c
index e6f01417a61453fd4b28dec489351703b3bd69d7..977e131fbeda106fcaa8fe7964af878ccbe2ebe9 100644 (file)
--- a/util.c
+++ b/util.c
@@ -427,6 +427,11 @@ const char *priomsg_getmessage(const struct priomsg *pm, const char *defmsg)
        return defmsg;
 }
 
+bool_t priomsg_update_fixed(struct priomsg *pm, int prio, const char *m) {
+    if (!priomsg_update_p(pm, prio)) return False;
+    truncmsg_add_string(&pm->m, m);
+    return True;
+}
 
 void buffer_new(struct buffer_if *buf, int32_t len)
 {
diff --git a/util.h b/util.h
index eddb06db3f57667ca1a9506db6076726110c73e7..a2ef82864b84d247de94e21ca4c46b8eb079f6f6 100644 (file)
--- a/util.h
+++ b/util.h
@@ -81,6 +81,9 @@ const char *priomsg_getmessage(const struct priomsg *pm, const char *defmsg);
   /* return value is null-terminated, valid until next call
    * or until defmsg is no longer valid                                ZM */
 
+bool_t priomsg_update_fixed(struct priomsg *pm, int prio, const char *m);
+  /* convenience combination of _update_p and truncmsg_add_string */
+
 /*
  * void BUF_ADD_BYTES(append,    struct buffer_if*, const void*, int32_t size);
  * void BUF_ADD_BYTES(prepend,   struct buffer_if*, const void*, int32_t size);