]>
Commit | Line | Data |
---|---|---|
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 | ||
31 | int close_nointr(int fd); | |
32 | int safe_close(int fd); | |
33 | void safe_close_pair(int p[]); | |
34 | ||
35 | void close_many(const int fds[], unsigned n_fd); | |
36 | ||
37 | int fclose_nointr(FILE *f); | |
38 | FILE* safe_fclose(FILE *f); | |
39 | DIR* safe_closedir(DIR *f); | |
40 | ||
41 | static inline void closep(int *fd) { | |
42 | safe_close(*fd); | |
43 | } | |
44 | ||
45 | static inline void close_pairp(int (*p)[2]) { | |
46 | safe_close_pair(*p); | |
47 | } | |
48 | ||
49 | static inline void fclosep(FILE **f) { | |
50 | safe_fclose(*f); | |
51 | } | |
52 | ||
53 | DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, pclose); | |
54 | DEFINE_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 | ||
62 | int fd_nonblock(int fd, bool nonblock); | |
63 | int fd_cloexec(int fd, bool cloexec); | |
64 | ||
65 | int close_all_fds(const int except[], unsigned n_except); | |
66 | ||
67 | int same_fd(int a, int b); | |
68 | ||
69 | void cmsg_close_all(struct msghdr *mh); |