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