Port: use ghashtable in mman compat
[babeltrace.git] / tests / lib / common.c
CommitLineData
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>
3d9990ac
PP
24#include <babeltrace/compat/dirent-internal.h>
25#include <babeltrace/compat/limits-internal.h>
851299b9 26#include <sys/stat.h>
aa968dde 27
851299b9
JG
28void recursive_rmdir(const char *path)
29{
30 struct dirent *entry;
31 DIR *dir = opendir(path);
32
33 if (!dir) {
34 perror("# opendir");
35 return;
36 }
37
38 while ((entry = readdir(dir))) {
39 struct stat st;
40 char filename[PATH_MAX];
41
42 if (snprintf(filename, sizeof(filename), "%s/%s",
43 path, entry->d_name) <= 0) {
44 continue;
45 }
46
47 if (stat(filename, &st)) {
48 continue;
49 }
50
51 if (S_ISREG(st.st_mode)) {
52 unlinkat(bt_dirfd(dir), entry->d_name, 0);
53 }
54 }
55
56 rmdir(path);
57 closedir(dir);
58}
This page took 0.038744 seconds and 4 git commands to generate.