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