]> git.kaiwu.me - klib.git/commitdiff
added ks_resize()
authorHeng Li <lh3@live.co.uk>
Fri, 23 Sep 2011 04:04:11 +0000 (00:04 -0400)
committerHeng Li <lh3@live.co.uk>
Fri, 23 Sep 2011 04:04:11 +0000 (00:04 -0400)
kstring.h

index 73fcc6b9fd5f5688678b8cdfaaee3a89e4bf9c5f..89a7920c646fd6df2dc773250b7a0f5f1195ccec 100644 (file)
--- a/kstring.h
+++ b/kstring.h
@@ -67,7 +67,16 @@ extern "C" {
 #ifdef __cplusplus
 }
 #endif
-       
+
+static inline void ks_resize(kstring_t *s, size_t size)
+{
+       if (s->m < size) {
+               s->m = size;
+               kroundup32(s->m);
+               s->s = (char*)realloc(s->s, s->m);
+       }
+}
+
 static inline int kputsn(const char *p, int l, kstring_t *s)
 {
        if (s->l + l + 1 >= s->m) {