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;
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;
-// Concatenate strigns onto the heap if possible, or malloc new.
+// Concatenate strings onto the heap if possible, or malloc new.
extern char *strjoin(const char *first,...);
+// Allocate buffer space from the heap
+extern char *stralloc(int size);
+
// Dispose memory possibly within the string heap
extern void strfree(char *p);