]>
Commit | Line | Data |
---|---|---|
db2df898 MP |
1 | #pragma once |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include <dirent.h> | |
4c89c718 MP |
23 | #include <errno.h> |
24 | #include <stdbool.h> | |
db2df898 | 25 | |
4c89c718 | 26 | #include "macro.h" |
db2df898 MP |
27 | #include "path-util.h" |
28 | ||
29 | int dirent_ensure_type(DIR *d, struct dirent *de); | |
30 | ||
31 | bool dirent_is_file(const struct dirent *de) _pure_; | |
32 | bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; | |
33 | ||
34 | #define FOREACH_DIRENT(de, d, on_error) \ | |
35 | for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ | |
36 | if (!de) { \ | |
37 | if (errno > 0) { \ | |
38 | on_error; \ | |
39 | } \ | |
40 | break; \ | |
41 | } else if (hidden_file((de)->d_name)) \ | |
42 | continue; \ | |
43 | else | |
44 | ||
45 | #define FOREACH_DIRENT_ALL(de, d, on_error) \ | |
46 | for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ | |
47 | if (!de) { \ | |
48 | if (errno > 0) { \ | |
49 | on_error; \ | |
50 | } \ | |
51 | break; \ | |
52 | } else |