From 64c62439cd25a54abe5e1712af806995576beec3 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 18 Jul 2022 22:18:08 +0200 Subject: [PATCH] Fix a bunch of issues with the new temp file generation. --- mach/proto/mcg/mcg.h | 1 - modules/src/data/astring.c | 2 +- modules/src/data/astring.h | 2 +- modules/src/system/aprintf.c | 28 ---------------------------- modules/src/system/build.lua | 4 +++- modules/src/system/maketempfile.c | 7 +++++-- util/ack/build.lua | 1 + util/arch/build.lua | 1 + util/ass/build.lua | 2 +- util/ego/build.lua | 3 +++ util/opt/build.lua | 1 + 11 files changed, 17 insertions(+), 35 deletions(-) delete mode 100644 modules/src/system/aprintf.c diff --git a/mach/proto/mcg/mcg.h b/mach/proto/mcg/mcg.h index 9991d5001..69f194e85 100644 --- a/mach/proto/mcg/mcg.h +++ b/mach/proto/mcg/mcg.h @@ -79,7 +79,6 @@ struct em } u; }; -extern const char* aprintf(const char* fmt, ...); extern void tracef(char k, const char* fmt, ...); extern bool tracing(char k); diff --git a/modules/src/data/astring.c b/modules/src/data/astring.c index 7da06e9fa..097d9f4ad 100644 --- a/modules/src/data/astring.c +++ b/modules/src/data/astring.c @@ -2,7 +2,7 @@ #include #include -const char* aprintf(const char* fmt, ...) +char* aprintf(const char* fmt, ...) { int n; char* p; diff --git a/modules/src/data/astring.h b/modules/src/data/astring.h index 483c0287d..d1fffa807 100644 --- a/modules/src/data/astring.h +++ b/modules/src/data/astring.h @@ -1,7 +1,7 @@ #ifndef ASTRING_H #define ASTRING_H -extern const char* aprintf(const char* fmt, ...); +extern char* aprintf(const char* fmt, ...); #endif diff --git a/modules/src/system/aprintf.c b/modules/src/system/aprintf.c deleted file mode 100644 index 997d408c2..000000000 --- a/modules/src/system/aprintf.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include "system.h" - -char* aprintf(const char* fmt, ...) -{ - int n; - char* p; - va_list ap; - - va_start(ap, fmt); - n = vsnprintf(NULL, 0, fmt, ap) + 1; - va_end(ap); - - p = malloc(n); - if (!p) - return NULL; - - va_start(ap, fmt); - vsnprintf(p, n, fmt, ap); - va_end(ap); - - return p; -} - -/* vim: set sw=4 ts=4 expandtab : */ - diff --git a/modules/src/system/build.lua b/modules/src/system/build.lua index c19a82924..500cd59f2 100644 --- a/modules/src/system/build.lua +++ b/modules/src/system/build.lua @@ -2,7 +2,6 @@ clibrary { name = "lib", srcs = { "./access.c", - "./aprintf.c", "./basename.c", "./break.c", "./chmode.c", @@ -27,4 +26,7 @@ clibrary { --"./unlock.c”, }, hdrs = { "./system.h" }, + deps = { + "modules/src/data+lib", + } } diff --git a/modules/src/system/maketempfile.c b/modules/src/system/maketempfile.c index 02068b628..83accf8f9 100644 --- a/modules/src/system/maketempfile.c +++ b/modules/src/system/maketempfile.c @@ -7,6 +7,7 @@ #include #include #include "system.h" +#include "astring.h" #if defined WIN32 static unsigned temper(unsigned x) @@ -20,7 +21,8 @@ static unsigned temper(unsigned x) static int rand_r(unsigned *seed) { - return temper(*seed = *seed * 1103515245 + 12345)/2; + *seed = *seed * 1103515245 + 12345; + return temper(*seed)/2; } #endif @@ -36,8 +38,9 @@ char* sys_maketempfile(const char* prefix, const char* suffix) for (;;) { unsigned int hash = rand_r(&seed); - char* filename = aprintf("%s/ack-%s-%x%s", + char* filename = aprintf("%s/ack.%s-%x%s%s", tempdir, prefix, hash, + ((*suffix == 0) || (*suffix == '.')) ? "" : ".", suffix); int fd = open(filename, O_CREAT|O_EXCL|O_RDWR, 0600); if (fd != -1) diff --git a/util/ack/build.lua b/util/ack/build.lua index cf4dc9035..cd865332b 100644 --- a/util/ack/build.lua +++ b/util/ack/build.lua @@ -34,6 +34,7 @@ cprogram { deps = { "h+emheaders", "h+local", + "modules/src/data+lib", "modules/src/system+lib", "./ack.h", "./data.h", diff --git a/util/arch/build.lua b/util/arch/build.lua index 160b9c21f..eff8e22ad 100644 --- a/util/arch/build.lua +++ b/util/arch/build.lua @@ -3,6 +3,7 @@ cprogram { srcs = { "./archiver.c" }, deps = { "h+emheaders", + "modules/src/data+lib", "modules/src/object+lib", "modules/src/print+lib", "modules/src/string+lib", diff --git a/util/ass/build.lua b/util/ass/build.lua index d976e1bf0..f46668cc8 100644 --- a/util/ass/build.lua +++ b/util/ass/build.lua @@ -44,7 +44,7 @@ cprogram { "h+local", --"modules/src/alloc+lib", "modules/src/em_data+lib", - --"modules/src/data+lib", + "modules/src/data+lib", --"modules/src/object+lib", "modules/src/system+lib", "./ass00.h", diff --git a/util/ego/build.lua b/util/ego/build.lua index 5d7768e7e..8749fe40d 100644 --- a/util/ego/build.lua +++ b/util/ego/build.lua @@ -40,6 +40,7 @@ cprogram { "./ca/ca_put.h", "util/ego/share+lib", "modules/src/em_data+lib", + "modules/src/data+lib", "modules/src/system+lib", "h+emheaders", }, @@ -177,6 +178,7 @@ cprogram { "./il/il.h", "util/ego/share+lib", "modules/src/em_data+lib", + "modules/src/data+lib", "modules/src/system+lib", "h+emheaders", }, @@ -275,6 +277,7 @@ cprogram { "modules/src/print+lib", "modules/src/string+lib", "modules/src/system+lib", + "modules/src/data+lib", "modules+headers", "h+emheaders", } diff --git a/util/opt/build.lua b/util/opt/build.lua index d62858042..ec213d879 100644 --- a/util/opt/build.lua +++ b/util/opt/build.lua @@ -84,6 +84,7 @@ local function variant(name, cflags) "modules/src/print+lib", "modules/src/string+lib", "modules/src/system+lib", + "modules/src/data+lib", "modules/src/em_data+lib" ), vars = {