diff --git a/usr.sbin/mfiutil/mfi_bbu.c b/usr.sbin/mfiutil/mfi_bbu.c --- a/usr.sbin/mfiutil/mfi_bbu.c +++ b/usr.sbin/mfiutil/mfi_bbu.c @@ -40,41 +40,23 @@ /* The autolearn period is given in seconds. */ void -mfi_autolearn_period(uint32_t period, char *buf, size_t sz) +mfi_autolearn_period(FILE *fp, uint32_t period) { unsigned int d, h; - char *tmp; d = period / (24 * 3600); h = (period % (24 * 3600)) / 3600; - tmp = buf; if (d != 0) { - int fmt_len; - fmt_len = snprintf(buf, sz, "%u day%s", d, d == 1 ? "" : "s"); - if (fmt_len < 0) { - *buf = 0; - return; - } - if ((size_t)fmt_len >= sz) { - return; - } - tmp += fmt_len; - sz -= tmp - buf; - if (h != 0) { - fmt_len = snprintf(tmp, sz, ", "); - if (fmt_len < 0 || (size_t)fmt_len >= sz) { - return; - } - tmp += fmt_len; - sz -= 2; - } + fprintf(fp, "%u day%s", d, d == 1 ? "" : "s"); + if (h != 0) + fprintf(fp, ", "); } if (h != 0) - snprintf(tmp, sz, "%u hour%s", h, h == 1 ? "" : "s"); + fprintf(fp, "%u hour%s", h, h == 1 ? "" : "s"); if (d == 0 && h == 0) - snprintf(tmp, sz, "less than 1 hour"); + fprintf(fp, "less than 1 hour"); } /* The time to the next relearn is given in seconds since 1/1/2000. */ @@ -96,21 +78,21 @@ } void -mfi_autolearn_mode(uint8_t mode, char *buf, size_t sz) +mfi_autolearn_mode(FILE *fp, uint8_t mode) { switch (mode) { case 0: - snprintf(buf, sz, "enabled"); + fprintf(fp, "enabled"); break; case 1: - snprintf(buf, sz, "disabled"); + fprintf(fp, "disabled"); break; case 2: - snprintf(buf, sz, "warn via event"); + fprintf(fp, "warn via event"); break; default: - snprintf(buf, sz, "mode 0x%02x", mode); + fprintf(fp, "mode 0x%02x", mode); break; } } diff --git a/usr.sbin/mfiutil/mfi_show.c b/usr.sbin/mfiutil/mfi_show.c --- a/usr.sbin/mfiutil/mfi_show.c +++ b/usr.sbin/mfiutil/mfi_show.c @@ -218,8 +218,9 @@ printf(" Current Voltage: %d mV\n", stat.voltage); printf(" Temperature: %d C\n", stat.temperature); if (show_props) { - mfi_autolearn_period(props.auto_learn_period, buf, sizeof(buf)); - printf(" Autolearn period: %s\n", buf); + printf(" Autolearn period: "); + mfi_autolearn_period(stdout, props.auto_learn_period); + printf("\n"); if (props.auto_learn_mode != 0) snprintf(buf, sizeof(buf), "never"); else @@ -229,8 +230,9 @@ printf(" Learn delay interval: %u hour%s\n", props.learn_delay_interval, props.learn_delay_interval != 1 ? "s" : ""); - mfi_autolearn_mode(props.auto_learn_mode, buf, sizeof(buf)); - printf(" Autolearn mode: %s\n", buf); + printf(" Autolearn mode: "); + mfi_autolearn_mode(stdout, props.auto_learn_mode); + printf("\n"); if (props.bbu_mode != 0) printf(" BBU Mode: %d\n", props.bbu_mode); } diff --git a/usr.sbin/mfiutil/mfiutil.h b/usr.sbin/mfiutil/mfiutil.h --- a/usr.sbin/mfiutil/mfiutil.h +++ b/usr.sbin/mfiutil/mfiutil.h @@ -175,9 +175,9 @@ uint8_t *statusp); int mfi_bbu_set_props(int fd, struct mfi_bbu_properties *props, uint8_t *statusp); -void mfi_autolearn_period(uint32_t, char *, size_t); +void mfi_autolearn_period(FILE *, uint32_t); void mfi_next_learn_time(uint32_t, char *, size_t); -void mfi_autolearn_mode(uint8_t, char *, size_t); +void mfi_autolearn_mode(FILE *, uint8_t); int get_mfi_unit(const char *dev); char *get_mfi_type(const char *dev);