stralloc.h (1632B)
1 /* ISC license. */ 2 3 #ifndef SKALIBS_STRALLOC_H 4 #define SKALIBS_STRALLOC_H 5 6 #include <string.h> 7 #include <sys/uio.h> 8 9 typedef struct stralloc_s stralloc, *stralloc_ref ; 10 struct stralloc_s 11 { 12 char *s ; 13 size_t len ; 14 size_t a ; 15 } ; 16 17 #define STRALLOC_ZERO { 0, 0, 0 } 18 extern stralloc const stralloc_zero ; 19 20 extern int stralloc_ready_tuned (stralloc *, size_t, size_t, size_t, size_t) ; 21 extern int stralloc_readyplus_tuned (stralloc *, size_t, size_t, size_t, size_t) ; 22 #define stralloc_ready(sa, n) stralloc_ready_tuned(sa, (n), 8, 1, 8) 23 #define stralloc_readyplus(sa, n) stralloc_readyplus_tuned(sa, (n), 8, 1, 8) 24 extern void stralloc_free (stralloc *) ; 25 extern int stralloc_shrink (stralloc *) ; 26 extern int stralloc_copyb (stralloc *, char const *, size_t) ; 27 extern int stralloc_catb (stralloc *, char const *, size_t) ; 28 extern int stralloc_catv (stralloc *, struct iovec const *, unsigned int) ; 29 #define stralloc_copys(sa, s) stralloc_copyb(sa, (s), strlen(s)) 30 #define stralloc_cats(sa, s) stralloc_catb(sa, (s), strlen(s)) 31 #define stralloc_copy(sa1, sa2) stralloc_copyb(sa1, (sa2)->s, (sa2)->len) 32 #define stralloc_cat(sa1, sa2) stralloc_catb(sa1, (sa2)->s, (sa2)->len) 33 extern int stralloc_append (stralloc *, char) ; 34 extern void stralloc_reverse (stralloc *) ; 35 extern void stralloc_reverse_blocks (stralloc *, size_t) ; 36 #define stralloc_0(sa) stralloc_catb(sa, "", 1) 37 extern int stralloc_insertb (stralloc *, size_t, char const *, size_t) ; 38 #define stralloc_inserts(sa, offset, s) stralloc_insertb(sa, offset, (s), strlen(s)) 39 #define stralloc_insert(sa1, offset, sa2) stralloc_insertb(sa1, offset, (sa2)->s, (sa2)->len) 40 41 #endif