X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Futils%2Fcommon.c;fp=tests%2Futils%2Fcommon.c;h=1878d777d3eba4b78f43523a4dcc8f48fd8719a0;hb=550b7a4e67a46d1de6b3e83b010b6d38b1c5e7d4;hp=0000000000000000000000000000000000000000;hpb=c88dd1cb8e4858f962f417943983cb39c1a2c245;p=babeltrace.git diff --git a/tests/utils/common.c b/tests/utils/common.c new file mode 100644 index 00000000..1878d777 --- /dev/null +++ b/tests/utils/common.c @@ -0,0 +1,50 @@ +/* + * common.c + * + * Lib BabelTrace - Common function to all tests + * + * Copyright 2012 - Yannick Brosseau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +#define RMDIR_NFDOPEN 8 + +static +int nftw_recursive_rmdir(const char *file, const struct stat *sb, int flag, + struct FTW *s) +{ + 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); +}