void statusfd_send(const char *fmt, ...) { static struct varbuf vb; struct pipef *pipef; va_list args; if (!status_pipes) return; va_start(args, fmt); varbuf_reset(&vb); varbuf_vprintf(&vb, fmt, args); /* Sanitize string to not include new lines, as front-ends should be * doing their own word-wrapping. */ varbuf_map_char(&vb, '\n', ' '); varbuf_add_char(&vb, '\n'); va_end(args); for (pipef = status_pipes; pipef; pipef = pipef->next) { if (fd_write(pipef->fd, vb.buf, vb.used) < 0) ohshite(_("unable to write to status fd %d"), pipef->fd); } }
static void test_varbuf_map_char(void) { struct varbuf vb; varbuf_init(&vb, 5); varbuf_add_buf(&vb, "1234a5678a9012a", 15); varbuf_map_char(&vb, 'a', 'z'); test_pass(vb.used == 15); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234z5678z9012z", 15); varbuf_destroy(&vb); }