summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-11-17 18:33:14 +0100
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-11-17 18:33:14 +0100
commit797796e2d9d4c708668ed05359695c53f8448386 (patch)
treed97c7fbe4742c62ed8e92a710a8cc4b916304d3f
parent5304bcb44ff71ddfa02af3bff4d05812b4fc4be3 (diff)
downloadratpoison-797796e2d9d4c708668ed05359695c53f8448386.zip
Introduce sbuf_chop()
-rw-r--r--src/sbuf.c9
-rw-r--r--src/sbuf.h4
2 files changed, 11 insertions, 2 deletions
diff --git a/src/sbuf.c b/src/sbuf.c
index 8e4556d..055006d 100644
--- a/src/sbuf.c
+++ b/src/sbuf.c
@@ -143,3 +143,12 @@ sbuf_printf_concat (struct sbuf *b, char *fmt, ...)
return b->data;
}
+
+void
+sbuf_chop (struct sbuf *b)
+{
+ if (b->len)
+ {
+ b->data[--(b->len)] = '\0';
+ }
+}
diff --git a/src/sbuf.h b/src/sbuf.h
index ae4ea9c..e565efc 100644
--- a/src/sbuf.h
+++ b/src/sbuf.h
@@ -24,8 +24,7 @@
#include <stdlib.h>
-struct
-sbuf
+struct sbuf
{
char *data;
size_t len;
@@ -45,5 +44,6 @@ char *sbuf_clear (struct sbuf *b);
char *sbuf_get (struct sbuf *b);
char *sbuf_printf (struct sbuf *b, char *fmt, ...);
char *sbuf_printf_concat (struct sbuf *b, char *fmt, ...);
+void sbuf_chop (struct sbuf *b);
#endif /* ! _RATPOISON_SBUF_H */