X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=stringmem.c;h=bc1a2bf150786ed5a17fda10f02d66e4752588d0;hb=HEAD;hp=303add79f6621dbb8d7b8f2e1c568b9faf72ea12;hpb=186796e391585f79f86d4aebc274dcaa78f58769;p=rrq%2Ffuse_xattrs.git diff --git a/stringmem.c b/stringmem.c index 303add7..bc1a2bf 100644 --- a/stringmem.c +++ b/stringmem.c @@ -3,7 +3,7 @@ #include #define BIGSTRING 1048576 -#define STRINGSPACE ( BIGSTRING * 20 ) +#define STRINGSPACE ( BIGSTRING * 50 ) static struct { char *base; @@ -11,13 +11,27 @@ static struct { char *end; } heap; -char *strjoin(const char *first,...) { - va_list ap; +static inline void strinitialize() { if ( heap.base == 0 ) { heap.base = (char*) malloc( STRINGSPACE ); heap.current = heap.base; heap.end = heap.base + STRINGSPACE; } +} + +extern char *stralloc(int size) { + strinitialize(); + if ( heap.current + size >= heap.end ) { + heap.current = heap.base; + } + char *start = heap.current; + heap.current += size; + return start; +} + +char *strjoin(const char *first,...) { + va_list ap; + strinitialize(); char *start = heap.current; const char *p = first; size_t size = strlen( first ) + 1; @@ -29,7 +43,7 @@ char *strjoin(const char *first,...) { if ( size > BIGSTRING ) { start = (char*) malloc( size ); } else { - if ( heap.current + size > heap.end ) { + if ( heap.current + size >= heap.end ) { heap.current = heap.base; } start = heap.current;