t-reftable-stack: use Git's tempfile API instead of mkstemp()

Git's tempfile API defined by $GIT_DIR/tempfile.{c,h} provides a unified interface for tempfile operations. Since reftable/stack.c uses this API for all its tempfile needs instead of raw functions like mkstemp(), make the ported stack test strictly use Git's tempfile API as well. A bigger benefit is the fact that we know to clean up the tempfile in case the test fails because it gets registered and pruned via a signal handler. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chandra Pratap committed Sep 8, 2024 at 09:35 UTC 476abc39babbdc67782ad04c4fa1d965ca8ff34d
1 file changed +3 -1
t/unit-tests/t-reftable-stack.c
+3 -1
@@ -76,7 +76,8 @@ static char *get_tmp_dir(int linenumber)
76 static void t_read_file(void)
77 {
78 char *fn = get_tmp_template(__LINE__);
79 - int fd = mkstemp(fn);
79 + struct tempfile *tmp = mks_tempfile(fn);
80 + int fd = get_tempfile_fd(tmp);
81 char out[1024] = "line1\n\nline2\nline3";
82 int n, err;
83 char **names = NULL;
@@ -95,6 +96,7 @@ static void t_read_file(void)
96 check_str(want[i], names[i]);
97 free_names(names);
98 (void) remove(fn);
99 + delete_tempfile(&tmp);
100 }
101
102 static int write_test_ref(struct reftable_writer *wr, void *arg)