X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=stringmem.c;h=1a6bf00e89d6e0f43c79e1a668e155c9d850509e;hb=37f43d2aa3f135a7fff1ca03552a4468b07f3390;hp=303add79f6621dbb8d7b8f2e1c568b9faf72ea12;hpb=a93f22e050e3bc971f341ab4580d39266713133b;p=rrq%2Ffuse_xattrs.git diff --git a/stringmem.c b/stringmem.c index 303add7..1a6bf00 100644 --- a/stringmem.c +++ b/stringmem.c @@ -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;