X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Flib%2Fcommon.c;h=d137cb304a764f3a3680af7284fbb1c60aad6054;hb=851299b967aa3565bdaf44ee7001dabbabf7c787;hp=60e2be04244a34b821d5e93bb14a57d85530e42d;hpb=8684abc83fb68af80191e7d32f1054db055aafb8;p=babeltrace.git diff --git a/tests/lib/common.c b/tests/lib/common.c index 60e2be04..d137cb30 100644 --- a/tests/lib/common.c +++ b/tests/lib/common.c @@ -21,6 +21,8 @@ #include #include +#include +#include struct bt_context *create_context_with_path(const char *path) { @@ -39,3 +41,35 @@ struct bt_context *create_context_with_path(const char *path) } return ctx; } + +void recursive_rmdir(const char *path) +{ + struct dirent *entry; + DIR *dir = opendir(path); + + if (!dir) { + perror("# opendir"); + return; + } + + while ((entry = readdir(dir))) { + struct stat st; + char filename[PATH_MAX]; + + if (snprintf(filename, sizeof(filename), "%s/%s", + path, entry->d_name) <= 0) { + continue; + } + + if (stat(filename, &st)) { + continue; + } + + if (S_ISREG(st.st_mode)) { + unlinkat(bt_dirfd(dir), entry->d_name, 0); + } + } + + rmdir(path); + closedir(dir); +}