a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering#pragma once
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering/***
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering This file is part of systemd.
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering Copyright 2010 Lennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering systemd is free software; you can redistribute it and/or modify it
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering under the terms of the GNU Lesser General Public License as published by
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering (at your option) any later version.
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering systemd is distributed in the hope that it will be useful, but
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering Lesser General Public License for more details.
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering You should have received a copy of the GNU Lesser General Public License
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering***/
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering#include <dirent.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <errno.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <stdbool.h>
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include "macro.h"
93cc7779e0c121b75183920173f37cd1ee9d59cfThomas Hindoe Paaboel Andersen#include "path-util.h"
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poetteringint dirent_ensure_type(DIR *d, struct dirent *de);
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poetteringbool dirent_is_file(const struct dirent *de) _pure_;
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poetteringbool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering#define FOREACH_DIRENT(de, d, on_error) \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering if (!de) { \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering if (errno > 0) { \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering on_error; \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering } \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering break; \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering } else if (hidden_file((de)->d_name)) \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering continue; \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering else
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering#define FOREACH_DIRENT_ALL(de, d, on_error) \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering if (!de) { \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering if (errno > 0) { \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering on_error; \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering } \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering break; \
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering } else