File: common.c

package info (click to toggle)
babeltrace2 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,660 kB
  • sloc: cpp: 106,162; ansic: 78,276; python: 27,115; sh: 9,053; makefile: 1,807; xml: 46
file content (41 lines) | stat: -rw-r--r-- 706 bytes parent folder | download | duplicates (2)
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
/*
 * SPDX-License-Identifier: GPL-2.0-only
 *
 * Copyright (C) 2012 Yannick Brosseau <yannick.brosseau@gmail.com>
 *
 * Lib BabelTrace - Common function to all tests
 */

#include "common.h"

#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <ftw.h>

#define RMDIR_NFDOPEN 8

static
int nftw_recursive_rmdir(const char *file,
		const struct stat *sb __attribute__((unused)),
		int flag,
		struct FTW *s __attribute__((unused)))
{
	switch (flag) {
	case FTW_F:
		unlink(file);
		break;
	case FTW_DP:
		rmdir(file);
		break;
	}

	return 0;
}

void recursive_rmdir(const char *path)
{
	int nftw_flags = FTW_PHYS | FTW_DEPTH;

	nftw(path, nftw_recursive_rmdir, RMDIR_NFDOPEN, nftw_flags);
}