]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/fd-util.h
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / basic / fd-util.h
CommitLineData
3ffd4af2
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 <stdio.h>
25#include <dirent.h>
26#include <stdbool.h>
27#include <sys/socket.h>
28
29#include "macro.h"
30
31int close_nointr(int fd);
32int safe_close(int fd);
33void safe_close_pair(int p[]);
34
35void close_many(const int fds[], unsigned n_fd);
36
37int fclose_nointr(FILE *f);
38FILE* safe_fclose(FILE *f);
39DIR* safe_closedir(DIR *f);
40
41static inline void closep(int *fd) {
42 safe_close(*fd);
43}
44
45static inline void close_pairp(int (*p)[2]) {
46 safe_close_pair(*p);
47}
48
49static inline void fclosep(FILE **f) {
50 safe_fclose(*f);
51}
52
53DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose);
54DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
55
56#define _cleanup_close_ _cleanup_(closep)
57#define _cleanup_fclose_ _cleanup_(fclosep)
58#define _cleanup_pclose_ _cleanup_(pclosep)
59#define _cleanup_closedir_ _cleanup_(closedirp)
60#define _cleanup_close_pair_ _cleanup_(close_pairp)
61
62int fd_nonblock(int fd, bool nonblock);
63int fd_cloexec(int fd, bool cloexec);
64
65int close_all_fds(const int except[], unsigned n_except);
66
67int same_fd(int a, int b);
68
69void cmsg_close_all(struct msghdr *mh);