FILE* f = NULL;
// Create a backend storage file
- ASSERT(f = test_mktemp());
+ ASSERT(f = test_mktemp(NULL));
// Open compressed file for writing
f = function(f, "w");
ASSERT_SUCCESS(pakfire_packager_add(packager, path, NULL));
// Write archive
- FILE* f = test_mktemp();
+ FILE* f = test_mktemp(NULL);
r = pakfire_packager_finish(packager, f);
ASSERT(r == 0);
#include <pakfire/pakfire.h>
#include <pakfire/util.h>
+#define TMP_TEMPLATE "/tmp/pakfire-test.XXXXXX"
+
struct testsuite ts;
static int test_run(int i, struct test* t) {
return EXIT_SUCCESS;
}
-FILE* test_mktemp() {
- char path[] = "/tmp/.pakfire-test.XXXXXX";
+FILE* test_mktemp(char** path) {
+ char* p = NULL;
+
+ // Reset path
+ if (path)
+ *path = NULL;
+
+ int r = asprintf(&p, "%s", TMP_TEMPLATE);
+ if (r < 0)
+ return NULL;
- int fd = mkstemp(path);
+ int fd = mkstemp(p);
if (fd < 0)
return NULL;
- // Immediately delete the temporary file
- unlink(path);
+ // If we want a named temporary file, we set path
+ if (path) {
+ *path = p;
+
+ // Otherwise we unlink the path and free p
+ } else {
+ unlink(p);
+ free(p);
+ }
return fdopen(fd, "w+");
}
char* test_mkdtemp() {
- char path[] = "/tmp/.pakfire-test.XXXXXX";
+ char path[] = TMP_TEMPLATE;
char* p = mkdtemp(path);
if (!p)