/src/rauc/subprojects/glib-2.76.5/glib/glib-unixprivate.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* glib-unixprivate.h - Unix specific integration private functions |
2 | | * |
3 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it under the terms of the GNU Lesser General Public |
7 | | * License as published by the Free Software Foundation; either |
8 | | * version 2.1 of the License, or (at your option) any later version. |
9 | | * |
10 | | * This library is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | | * Lesser General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU Lesser General Public License |
16 | | * along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | | */ |
18 | | |
19 | | #ifndef __G_UNIXPRIVATE_H__ |
20 | | #define __G_UNIXPRIVATE_H__ |
21 | | |
22 | | #include "config.h" |
23 | | |
24 | | #ifndef G_OS_UNIX |
25 | | #error "This header may only be used on UNIX" |
26 | | #endif |
27 | | |
28 | | /* To make bionic export pipe2() */ |
29 | | #ifndef _GNU_SOURCE |
30 | | #define _GNU_SOURCE 1 |
31 | | #endif |
32 | | |
33 | | #include "gmacros.h" |
34 | | #include "gtypes.h" |
35 | | |
36 | | #include <errno.h> |
37 | | #include <fcntl.h> |
38 | | #include <unistd.h> |
39 | | |
40 | | G_BEGIN_DECLS |
41 | | |
42 | | static inline gboolean |
43 | | g_unix_open_pipe_internal (int *fds, |
44 | | gboolean close_on_exec) |
45 | 0 | { |
46 | 0 | #ifdef HAVE_PIPE2 |
47 | 0 | do |
48 | 0 | { |
49 | 0 | int ecode; |
50 | | |
51 | | /* Atomic */ |
52 | 0 | ecode = pipe2 (fds, close_on_exec ? O_CLOEXEC : 0); |
53 | 0 | if (ecode == -1 && errno != ENOSYS) |
54 | 0 | return FALSE; |
55 | 0 | else if (ecode == 0) |
56 | 0 | return TRUE; |
57 | | /* Fall through on -ENOSYS, we must be running on an old kernel */ |
58 | 0 | } |
59 | 0 | while (FALSE); |
60 | 0 | #endif |
61 | | |
62 | 0 | if (pipe (fds) == -1) |
63 | 0 | return FALSE; |
64 | | |
65 | 0 | if (!close_on_exec) |
66 | 0 | return TRUE; |
67 | | |
68 | 0 | if (fcntl (fds[0], F_SETFD, FD_CLOEXEC) == -1 || |
69 | 0 | fcntl (fds[1], F_SETFD, FD_CLOEXEC) == -1) |
70 | 0 | { |
71 | 0 | int saved_errno = errno; |
72 | |
|
73 | 0 | close (fds[0]); |
74 | 0 | close (fds[1]); |
75 | 0 | fds[0] = -1; |
76 | 0 | fds[1] = -1; |
77 | |
|
78 | 0 | errno = saved_errno; |
79 | 0 | return FALSE; |
80 | 0 | } |
81 | | |
82 | 0 | return TRUE; |
83 | 0 | } |
84 | | |
85 | | G_END_DECLS |
86 | | |
87 | | #endif /* __G_UNIXPRIVATE_H__ */ |