summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-29 20:20:04 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-30 21:59:46 +0100
commit7ed66467ffe6dde9f4ca4975845d129772e4a851 (patch)
treea67cd316a13ec1f7afce8194f5a4e91f8296d1ad /misc.c
parent2a831de2a4232c4295964f4e048ff27e34a51661 (diff)
downloadhalibut-7ed66467ffe6dde9f4ca4975845d129772e4a851.zip
halibut-7ed66467ffe6dde9f4ca4975845d129772e4a851.tar.gz
halibut-7ed66467ffe6dde9f4ca4975845d129772e4a851.tar.bz2
halibut-7ed66467ffe6dde9f4ca4975845d129772e4a851.tar.xz
New utility function rdaddc_rep().
This is a function I should have introduced a lot earlier while writing the CHM output code, because I ended up with quite a lot of annoying loops to add zero-padding of various sizes by going round and round on the one-byte rdaddc().
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index 8a426f2..04c2e14 100644
--- a/misc.c
+++ b/misc.c
@@ -2,6 +2,7 @@
* misc.c: miscellaneous useful items
*/
+#include <assert.h>
#include <stdarg.h>
#include "halibut.h"
@@ -101,6 +102,19 @@ void rdaddsn(rdstringc *rs, char const *p, int len) {
rs->pos += len;
rs->text[rs->pos] = 0;
}
+void rdaddc_rep(rdstringc *rs, char c, int len) {
+ if (len <= 0) {
+ assert(len == 0);
+ return;
+ }
+ if (rs->pos >= rs->size - len) {
+ rs->size = rs->pos + len + 128;
+ rs->text = sresize(rs->text, rs->size, char);
+ }
+ memset(rs->text + rs->pos, c, len);
+ rs->pos += len;
+ rs->text[rs->pos] = 0;
+}
char *rdtrimc(rdstringc *rs) {
rs->text = sresize(rs->text, rs->pos + 1, char);
return rs->text;