Debian Codegraph @

test/lib/fs.c

raw
1 #include <ftw.h>
2 #include <stdio.h>
3 #include <sys/stat.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6
7 #include "fs.h"
8 #include "munit.h"
9
10 char *test_dir_setup()
11 {
12 char *dir = munit_malloc(strlen(TEST__DIR_TEMPLATE) + 1);
13
14 strcpy(dir, TEST__DIR_TEMPLATE);
15
16 munit_assert_ptr_not_null(mkdtemp(dir));
17
18 return dir;
19 }
20
21 static int test__dir_tear_down_nftw_fn(const char *path,
22 const struct stat *sb,
23 int type,
24 struct FTW *ftwb)
25 {
26 int rc;
27
28 (void)sb;
29 (void)type;
30 (void)ftwb;
31
32 rc = remove(path);
33 munit_assert_int(rc, ==, 0);
34
35 return 0;
36 }
37
38 void test_dir_tear_down(char *dir)
39 {
40 int rc;
41
42 if (dir == NULL) {
43 return;
44 }
45
46 rc = nftw(dir, test__dir_tear_down_nftw_fn, 10,
47 FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
48 munit_assert_int(rc, ==, 0);
49 free(dir);
50 }