Commit | Line | Data |
---|---|---|
aa968dde | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: GPL-2.0-only |
aa968dde | 3 | * |
0235b0db | 4 | * Copyright (C) 2012 Yannick Brosseau <yannick.brosseau@gmail.com> |
aa968dde | 5 | * |
0235b0db | 6 | * Lib BabelTrace - Common function to all tests |
aa968dde | 7 | */ |
aa968dde | 8 | |
7c7301d5 SM |
9 | #include "common.h" |
10 | ||
0aeee125 PP |
11 | #include <unistd.h> |
12 | #include <stdio.h> | |
ebd04048 | 13 | #include <dirent.h> |
e1f4c4f7 | 14 | #include <ftw.h> |
aa968dde | 15 | |
e1f4c4f7 | 16 | #define RMDIR_NFDOPEN 8 |
851299b9 | 17 | |
e1f4c4f7 | 18 | static |
ecd7492f MJ |
19 | int nftw_recursive_rmdir(const char *file, |
20 | const struct stat *sb __attribute__((unused)), | |
21 | int flag, | |
22 | struct FTW *s __attribute__((unused))) | |
e1f4c4f7 MJ |
23 | { |
24 | switch (flag) { | |
25 | case FTW_F: | |
26 | unlink(file); | |
27 | break; | |
28 | case FTW_DP: | |
29 | rmdir(file); | |
30 | break; | |
851299b9 JG |
31 | } |
32 | ||
e1f4c4f7 MJ |
33 | return 0; |
34 | } | |
851299b9 | 35 | |
e1f4c4f7 MJ |
36 | void recursive_rmdir(const char *path) |
37 | { | |
38 | int nftw_flags = FTW_PHYS | FTW_DEPTH; | |
851299b9 | 39 | |
e1f4c4f7 | 40 | nftw(path, nftw_recursive_rmdir, RMDIR_NFDOPEN, nftw_flags); |
851299b9 | 41 | } |