use larger string heap
[rrq/fuse_xattrs.git] / stringmem.c
index 303add79f6621dbb8d7b8f2e1c568b9faf72ea12..bc1a2bf150786ed5a17fda10f02d66e4752588d0 100644 (file)
@@ -3,7 +3,7 @@
 #include <string.h>
 
 #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;