]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-copy.c
util-lib: split out allocation calls into alloc-util.[ch]
[thirdparty/systemd.git] / src / test / test-copy.c
index e55ffaa16a5cfd5b77e8eeeff2aae71dfc977496..ad57cb0202f5cd4ae5d1cc0642708330368a96f2 100644 (file)
 
 #include <unistd.h>
 
+#include "alloc-util.h"
 #include "copy.h"
-#include "path-util.h"
+#include "fd-util.h"
 #include "fileio.h"
+#include "fs-util.h"
+#include "macro.h"
 #include "mkdir.h"
+#include "path-util.h"
+#include "rm-rf.h"
+#include "string-util.h"
 #include "strv.h"
-#include "macro.h"
 #include "util.h"
-#include "rm-rf.h"
 
 static void test_copy_file(void) {
         _cleanup_free_ char *buf = NULL;
@@ -43,7 +47,7 @@ static void test_copy_file(void) {
         assert_se(fd >= 0);
         close(fd);
 
-        assert_se(write_string_file(fn, "foo bar bar bar foo") == 0);
+        assert_se(write_string_file(fn, "foo bar bar bar foo", WRITE_STRING_FILE_CREATE) == 0);
 
         assert_se(copy_file(fn, fn_copy, 0, 0644, 0) == 0);
 
@@ -67,7 +71,7 @@ static void test_copy_file_fd(void) {
         out_fd = mkostemp_safe(out_fn, O_RDWR);
         assert_se(out_fd >= 0);
 
-        assert_se(write_string_file(in_fn, text) == 0);
+        assert_se(write_string_file(in_fn, text, WRITE_STRING_FILE_CREATE) == 0);
         assert_se(copy_file_fd("/a/file/which/does/not/exist/i/guess", out_fd, true) < 0);
         assert_se(copy_file_fd(in_fn, out_fd, true) >= 0);
         assert_se(lseek(out_fd, SEEK_SET, 0) == 0);
@@ -94,7 +98,7 @@ static void test_copy_tree(void) {
                 char *f = strjoina(original_dir, *p);
 
                 assert_se(mkdir_parents(f, 0755) >= 0);
-                assert_se(write_string_file(f, "file") == 0);
+                assert_se(write_string_file(f, "file", WRITE_STRING_FILE_CREATE) == 0);
         }
 
         STRV_FOREACH_PAIR(link, p, links) {
@@ -139,12 +143,14 @@ static void test_copy_bytes(void) {
         int r, r2;
         char buf[1024], buf2[1024];
 
-        infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC);
+        infd = open("/usr/lib/os-release", O_RDONLY|O_CLOEXEC);
+        if (infd < 0)
+                infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC);
         assert_se(infd >= 0);
 
         assert_se(pipe2(pipefd, O_CLOEXEC) == 0);
 
-        r = copy_bytes(infd, pipefd[1], (off_t) -1, false);
+        r = copy_bytes(infd, pipefd[1], (uint64_t) -1, false);
         assert_se(r == 0);
 
         r = read(pipefd[0], buf, sizeof(buf));