summaryrefslogtreecommitdiffstats
path: root/attributes.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-03-17 21:45:25 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-03-17 21:45:25 +0000
commit50f5d2a7ec9b3497a4d2c8ab4470ea2627edf5b9 (patch)
tree0b5e05126ef0a7944603f718a17e26249cc82241 /attributes.c
parent95f48a219a3b270e4e6b235745b094db4b7fe9f3 (diff)
Use snprintf for constructing attribute string, from Tim Ruehsen.
Diffstat (limited to 'attributes.c')
-rw-r--r--attributes.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/attributes.c b/attributes.c
index 81f29452..84e4f9c6 100644
--- a/attributes.c
+++ b/attributes.c
@@ -26,27 +26,21 @@ const char *
attributes_tostring(u_char attr)
{
static char buf[128];
+ size_t len;
if (attr == 0)
return ("none");
- buf[0] = '\0';
- if (attr & GRID_ATTR_BRIGHT)
- strlcat(buf, "bright,", sizeof (buf));
- if (attr & GRID_ATTR_DIM)
- strlcat(buf, "dim,", sizeof (buf));
- if (attr & GRID_ATTR_UNDERSCORE)
- strlcat(buf, "underscore,", sizeof (buf));
- if (attr & GRID_ATTR_BLINK)
- strlcat(buf, "blink,", sizeof (buf));
- if (attr & GRID_ATTR_REVERSE)
- strlcat(buf, "reverse,", sizeof (buf));
- if (attr & GRID_ATTR_HIDDEN)
- strlcat(buf, "hidden,", sizeof (buf));
- if (attr & GRID_ATTR_ITALICS)
- strlcat(buf, "italics,", sizeof (buf));
- if (*buf != '\0')
- *(strrchr(buf, ',')) = '\0';
+ len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s",
+ attr & GRID_ATTR_BRIGHT ? "bright," : "",
+ attr & GRID_ATTR_DIM ? "dim," : "",
+ attr & GRID_ATTR_UNDERSCORE ? "underscore," : "",
+ attr & GRID_ATTR_BLINK ? "blink," : "",
+ attr & GRID_ATTR_REVERSE ? "reverse," : "",
+ attr & GRID_ATTR_HIDDEN ? "hidden," : "",
+ attr & GRID_ATTR_ITALICS ? "italics," : "");
+ if (len > 0)
+ buf[len - 1] = '\0';
return (buf);
}