]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/dirent-util.h
basic: include only what we use
[thirdparty/systemd.git] / src / basic / dirent-util.h
CommitLineData
a0956174
LP
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>
11c3a366
TA
25#include <errno.h>
26#include <stdbool.h>
a0956174
LP
27
28#include "path-util.h"
11c3a366 29#include "macro.h"
a0956174
LP
30
31int dirent_ensure_type(DIR *d, struct dirent *de);
32
33bool dirent_is_file(const struct dirent *de) _pure_;
34bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
35
36#define FOREACH_DIRENT(de, d, on_error) \
37 for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
38 if (!de) { \
39 if (errno > 0) { \
40 on_error; \
41 } \
42 break; \
43 } else if (hidden_file((de)->d_name)) \
44 continue; \
45 else
46
47#define FOREACH_DIRENT_ALL(de, d, on_error) \
48 for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
49 if (!de) { \
50 if (errno > 0) { \
51 on_error; \
52 } \
53 break; \
54 } else