summaryrefslogtreecommitdiff
path: root/tests/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils.c')
-rw-r--r--tests/utils.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/utils.c b/tests/utils.c
index 21ef9d641d..512c3d40fc 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -29,6 +29,7 @@
#include <stdarg.h>
#include <time.h>
#include <unistd.h>
+#include <assert.h>
#include <errno.h>
#ifndef _WIN32
#include <netinet/in.h>
@@ -259,6 +260,28 @@ int main(int argc, char *argv[])
return error_count ? 1 : 0;
}
+struct tmp_file_st {
+ char file[TMPNAME_SIZE];
+ struct tmp_file_st *next;
+};
+
+static struct tmp_file_st *temp_files = (void*)-1;
+
+static void append(const char *file)
+{
+ struct tmp_file_st *p;
+
+ if (temp_files == (void*)-1)
+ return;
+
+ p = calloc(1, sizeof(*p));
+
+ assert(p != NULL);
+ strcpy(p->file, file);
+ p->next = temp_files;
+ temp_files = p;
+}
+
char *get_tmpname(char s[TMPNAME_SIZE])
{
unsigned char rnd[6];
@@ -283,5 +306,27 @@ char *get_tmpname(char s[TMPNAME_SIZE])
snprintf(p, TMPNAME_SIZE, "%s/tmpfile-%02x%02x%02x%02x%02x%02x.tmp", path, (unsigned)rnd[0], (unsigned)rnd[1],
(unsigned)rnd[2], (unsigned)rnd[3], (unsigned)rnd[4], (unsigned)rnd[5]);
+ append(p);
+
return p;
}
+
+void track_temp_files(void)
+{
+ temp_files = NULL;
+}
+
+void delete_temp_files(void)
+{
+ struct tmp_file_st *p = temp_files;
+ struct tmp_file_st *next;
+
+ if (p == (void*)-1)
+ return;
+
+ while(p != NULL) {
+ next = p->next;
+ free(p);
+ p = next;
+ }
+}