| 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 | */ |
| 21 | |
| 22 | #include "common.h" |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | #include <stdio.h> |
| 26 | #include <dirent.h> |
| 27 | #include <ftw.h> |
| 28 | |
| 29 | #define RMDIR_NFDOPEN 8 |
| 30 | |
| 31 | static |
| 32 | int nftw_recursive_rmdir(const char *file, const struct stat *sb, int flag, |
| 33 | struct FTW *s) |
| 34 | { |
| 35 | switch (flag) { |
| 36 | case FTW_F: |
| 37 | unlink(file); |
| 38 | break; |
| 39 | case FTW_DP: |
| 40 | rmdir(file); |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | void recursive_rmdir(const char *path) |
| 48 | { |
| 49 | int nftw_flags = FTW_PHYS | FTW_DEPTH; |
| 50 | |
| 51 | nftw(path, nftw_recursive_rmdir, RMDIR_NFDOPEN, nftw_flags); |
| 52 | } |