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