Fix a bunch of issues with the new temp file generation.

This commit is contained in:
David Given 2022-07-18 22:18:08 +02:00
parent 0cd26b1d0c
commit 64c62439cd
11 changed files with 17 additions and 35 deletions

View file

@ -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);

View file

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdarg.h>
const char* aprintf(const char* fmt, ...)
char* aprintf(const char* fmt, ...)
{
int n;
char* p;

View file

@ -1,7 +1,7 @@
#ifndef ASTRING_H
#define ASTRING_H
extern const char* aprintf(const char* fmt, ...);
extern char* aprintf(const char* fmt, ...);
#endif

View file

@ -1,28 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#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 : */

View file

@ -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",
}
}

View file

@ -7,6 +7,7 @@
#include <fcntl.h>
#include <errno.h>
#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)

View file

@ -34,6 +34,7 @@ cprogram {
deps = {
"h+emheaders",
"h+local",
"modules/src/data+lib",
"modules/src/system+lib",
"./ack.h",
"./data.h",

View file

@ -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",

View file

@ -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",

View file

@ -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",
}

View file

@ -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 = {