env-util: make write_env_file() optionally take headers

This also makes write_env_file() and write_env_file_label() optionally
take dir_fd, and drop write_env_file_at().

Preparation for later commits.
This commit is contained in:
Yu Watanabe
2023-10-31 17:15:21 +09:00
parent 78101ca9cc
commit f155cb6d75
10 changed files with 19 additions and 16 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ TEST(write_and_load_env_file) {
assert_se(tempfn_random_child(NULL, NULL, &p) >= 0);
assert_se(j = strjoin("TEST=", v));
assert_se(write_env_file(p, STRV_MAKE(j)) >= 0);
assert_se(write_env_file(AT_FDCWD, p, STRV_MAKE("# header 1", "", "# header 2"), STRV_MAKE(j)) >= 0);
assert_se(cmd = strjoin(". ", p, " && /bin/echo -n \"$TEST\""));
assert_se(f = popen(cmd, "re"));
+2 -2
View File
@@ -145,7 +145,7 @@ TEST(parse_env_file) {
assert_se(fd >= 0);
}
r = write_env_file(p, a);
r = write_env_file(AT_FDCWD, p, NULL, a);
assert_se(r >= 0);
r = load_env_file(NULL, p, &b);
@@ -208,7 +208,7 @@ TEST(parse_multiline_env_file) {
assert_se(fd >= 0);
}
r = write_env_file(p, a);
r = write_env_file(AT_FDCWD, p, NULL, a);
assert_se(r >= 0);
r = load_env_file(NULL, p, &b);