File: fs.c

package info (click to toggle)
dqlite 1.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,372 kB
  • sloc: ansic: 57,583; makefile: 336; sh: 243
file content (50 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <ftw.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "fs.h"
#include "munit.h"

char *test_dir_setup()
{
	char *dir = munit_malloc(strlen(TEST__DIR_TEMPLATE) + 1);

	strcpy(dir, TEST__DIR_TEMPLATE);

	munit_assert_ptr_not_null(mkdtemp(dir));

	return dir;
}

static int test__dir_tear_down_nftw_fn(const char *path,
				       const struct stat *sb,
				       int type,
				       struct FTW *ftwb)
{
	int rc;

	(void)sb;
	(void)type;
	(void)ftwb;

	rc = remove(path);
	munit_assert_int(rc, ==, 0);

	return 0;
}

void test_dir_tear_down(char *dir)
{
	int rc;

	if (dir == NULL) {
		return;
	}

	rc = nftw(dir, test__dir_tear_down_nftw_fn, 10,
		  FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
	munit_assert_int(rc, ==, 0);
	free(dir);
}