Commit | Line | Data |
---|---|---|
aa968dde YB |
1 | /* |
2 | * common.c | |
3 | * | |
4 | * Lib BabelTrace - Common function to all tests | |
5 | * | |
6 | * Copyright 2012 - Yannick Brosseau <yannick.brosseau@gmail.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; under version 2 of the License. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 | */ | |
aa968dde | 21 | |
0aeee125 PP |
22 | #include <unistd.h> |
23 | #include <stdio.h> | |
ebd04048 | 24 | #include <dirent.h> |
e1f4c4f7 | 25 | #include <ftw.h> |
aa968dde | 26 | |
e1f4c4f7 | 27 | #define RMDIR_NFDOPEN 8 |
851299b9 | 28 | |
e1f4c4f7 MJ |
29 | static |
30 | int nftw_recursive_rmdir(const char *file, const struct stat *sb, int flag, | |
31 | struct FTW *s) | |
32 | { | |
33 | switch (flag) { | |
34 | case FTW_F: | |
35 | unlink(file); | |
36 | break; | |
37 | case FTW_DP: | |
38 | rmdir(file); | |
39 | break; | |
851299b9 JG |
40 | } |
41 | ||
e1f4c4f7 MJ |
42 | return 0; |
43 | } | |
851299b9 | 44 | |
e1f4c4f7 MJ |
45 | void recursive_rmdir(const char *path) |
46 | { | |
47 | int nftw_flags = FTW_PHYS | FTW_DEPTH; | |
851299b9 | 48 | |
e1f4c4f7 | 49 | nftw(path, nftw_recursive_rmdir, RMDIR_NFDOPEN, nftw_flags); |
851299b9 | 50 | } |