diff options
| author | 2025-09-17 09:49:22 +0200 | |
|---|---|---|
| committer | 2025-09-17 09:49:22 +0200 | |
| commit | 960f79fa50009fd1e95a294547e3e46494d49484 (patch) | |
| tree | 93fbb3bb326f7efb8cfdfb249f0d1b76ef25d3bc /main.c | |
| parent | 3d0c49f4eb9e13e00bf12940b53da0f018c0a58c (diff) | |
alloc changes
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -52,6 +52,12 @@ ftdetect(const char *s) return IFTc; } +static union { + struct arena a; + char mem[sizeof(struct arena) + (1<<10)]; +} _arenamem; +struct arena *globarena = &_arenamem.a; + /* withext("x/y.c", "o") -> "y.o"; withext("f9", "s") -> "f9.s" */ static const char * withext(const char *path, const char *ext) @@ -69,7 +75,7 @@ withext(const char *path, const char *ext) len = strlen(file); else len = oext - file - 1; - res = xcalloc(len + 1 + strlen(ext) + 1); + res = alloc(&globarena, len + 1 + strlen(ext) + 1, 1); memcpy(res, file, len); res[len] = '.'; memcpy(res + len + 1, ext, strlen(ext)); @@ -193,8 +199,9 @@ tempfile(const char *path, const char *ext) else ioputc(&fbuf, '_'); } bfmt(&fbuf, "%s%s", &"."[!ext], ext ? ext : ""); + ioputc(&fbuf, 0); assert(!fbuf.err); - return memcpy(xcalloc(fbuf.len + 1), fbuf.buf, fbuf.len); + return alloccopy(&globarena, fbuf.buf, fbuf.len, 1); } static int cc1(const char *out, const char *in); @@ -345,6 +352,7 @@ int main(int argc, char **argv) { atexit(flushstd); + globarena->cap = sizeof(_arenamem.mem) - sizeof(struct arena); /* setup defaults */ detectcolor(); |