• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2017-2024 Cyril Hrubis <chrubis@suse.cz>
4  * Copyright (c) 2020 Martin Doucha <mdoucha@suse.cz>
5  */
6 
7 #ifndef TST_TMPDIR_H__
8 #define TST_TMPDIR_H__
9 
10 /**
11  * tst_purge_dir - Wipe the content of given directory.
12  *
13  * Wipe the content of given directory but keep the directory itself.
14  *
15  * @path: Path of the directory to be wiped.
16  */
17 void tst_purge_dir(const char *path);
18 
19 /**
20  * tst_tmpdir_path - Returns a pointer to a tmpdir path.
21  *
22  * The returned path is allocated and initialized the first time this function is
23  * called, each subsequent call will return the same pointer.
24  *
25  * return: A newly allocated path. The memory is freed automatically at the end
26  * of the test. If allocation fails the function calls tst_brk() and
27  * exits the test.
28  */
29 char *tst_tmpdir_path(void);
30 
31 /**
32  * tst_tmpdir_genpath - Construct an absolute path pointing to a file inside tmpdir.
33  *
34  * Constructs a path inside tmpdir i.e. adds a prefix pointing to the current
35  * test tmpdir to the string build by the printf-like format.
36  *
37  * @fmt: A printf-like format string.
38  * @...: A printf-like parameter list.
39  *
40  * return: A newly allocated path. The memory is freed automatically at the end
41  * of the test. If allocation fails the function calls tst_brk() and exits the
42  * test.
43  */
44 char *tst_tmpdir_genpath(const char *fmt, ...)
45 	__attribute__((format(printf, 1, 2)));
46 
47 /*
48  * Make sure nobody uses old API functions in new code.
49  */
50 #ifndef LTPLIB
51 # define tst_get_tmpdir #error Use tst_tmpdir_path()!
52 #endif
53 
54 #endif /* TST_TMPDIR_H__ */
55