Skip to content

Commit 476abc3

Browse files
Chandra Pratapgitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4e384f commit 476abc3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

t/unit-tests/t-reftable-stack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static char *get_tmp_dir(int linenumber)
7676
static void t_read_file(void)
7777
{
7878
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);
8081
char out[1024] = "line1\n\nline2\nline3";
8182
int n, err;
8283
char **names = NULL;
@@ -95,6 +96,7 @@ static void t_read_file(void)
9596
check_str(want[i], names[i]);
9697
free_names(names);
9798
(void) remove(fn);
99+
delete_tempfile(&tmp);
98100
}
99101

100102
static int write_test_ref(struct reftable_writer *wr, void *arg)

0 commit comments

Comments
 (0)