| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | #include <config.h> | - |
| 18 | | - |
| 19 | | - |
| 20 | #include <unistd.h> | - |
| 21 | | - |
| 22 | #include <errno.h> | - |
| 23 | #include <fcntl.h> | - |
| 24 | | - |
| 25 | #include "binary-io.h" | - |
| 26 | #include "verify.h" | - |
| 27 | | - |
| 28 | #if GNULIB_defined_O_NONBLOCK | - |
| 29 | # include "nonblocking.h" | - |
| 30 | #endif | - |
| 31 | | - |
| 32 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | - |
| 33 | | - |
| 34 | | - |
| 35 | # include <io.h> | - |
| 36 | | - |
| 37 | #endif | - |
| 38 | | - |
| 39 | int | - |
| 40 | pipe2 (int fd[2], int flags) | - |
| 41 | { | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | int tmp[2]; | - |
| 46 | tmp[0] = fd[0]; | - |
| 47 | tmp[1] = fd[1]; | - |
| 48 | | - |
| 49 | #if HAVE_PIPE2 | - |
| 50 | # undef pipe2 | - |
| 51 | | - |
| 52 | | - |
| 53 | { | - |
| 54 | | - |
| 55 | static int have_pipe2_really; | - |
| 56 | if (have_pipe2_really >= 0)| TRUE | evaluated 3720 times by 1 test | | FALSE | never evaluated |
| 0-3720 |
| 57 | { | - |
| 58 | int result = pipe2 (fd, flags); | - |
| 59 | if (!(result < 0 && errno == ENOSYS))| TRUE | never evaluated | | FALSE | evaluated 3720 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-3720 |
| 60 | { | - |
| 61 | have_pipe2_really = 1; | - |
| 62 | return result;executed 3720 times by 1 test: return result; | 3720 |
| 63 | } | - |
| 64 | have_pipe2_really = -1; | - |
| 65 | } never executed: end of block | 0 |
| 66 | } | - |
| 67 | #endif | - |
| 68 | | - |
| 69 | | - |
| 70 | if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_BINARY | O_TEXT)) != 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 71 | { | - |
| 72 | errno = EINVAL; | - |
| 73 | return -1; never executed: return -1; | 0 |
| 74 | } | - |
| 75 | | - |
| 76 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | - |
| 77 | | - |
| 78 | | - |
| 79 | if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0) | - |
| 80 | { | - |
| 81 | fd[0] = tmp[0]; | - |
| 82 | fd[1] = tmp[1]; | - |
| 83 | return -1; | - |
| 84 | } | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | # if GNULIB_defined_O_NONBLOCK | - |
| 90 | if (flags & O_NONBLOCK) | - |
| 91 | { | - |
| 92 | if (set_nonblocking_flag (fd[0], true) != 0 | - |
| 93 | || set_nonblocking_flag (fd[1], true) != 0) | - |
| 94 | goto fail; | - |
| 95 | } | - |
| 96 | # else | - |
| 97 | { | - |
| 98 | verify (O_NONBLOCK == 0); | - |
| 99 | } | - |
| 100 | # endif | - |
| 101 | | - |
| 102 | return 0; | - |
| 103 | | - |
| 104 | #else | - |
| 105 | | - |
| 106 | | - |
| 107 | if (pipe (fd) < 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 108 | return -1; never executed: return -1; | 0 |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | if (flags & O_NONBLOCK)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 117 | { | - |
| 118 | int fcntl_flags; | - |
| 119 | | - |
| 120 | if ((fcntl_flags = fcntl (fd[1], F_GETFL, 0)) < 0| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 121 | || fcntl (fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 122 | || (fcntl_flags = fcntl (fd[0], F_GETFL, 0)) < 0| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 123 | || fcntl (fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 124 | goto fail; never executed: goto fail; | 0 |
| 125 | } never executed: end of block | 0 |
| 126 | | - |
| 127 | if (flags & O_CLOEXEC)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 128 | { | - |
| 129 | int fcntl_flags; | - |
| 130 | | - |
| 131 | if ((fcntl_flags = fcntl (fd[1], F_GETFD, 0)) < 0| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 132 | || fcntl (fd[1], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 133 | || (fcntl_flags = fcntl (fd[0], F_GETFD, 0)) < 0| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 134 | || fcntl (fd[0], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 135 | goto fail; never executed: goto fail; | 0 |
| 136 | } never executed: end of block | 0 |
| 137 | | - |
| 138 | # if O_BINARY | - |
| 139 | if (flags & O_BINARY) | - |
| 140 | { | - |
| 141 | set_binary_mode (fd[1], O_BINARY); | - |
| 142 | set_binary_mode (fd[0], O_BINARY); | - |
| 143 | } | - |
| 144 | else if (flags & O_TEXT) | - |
| 145 | { | - |
| 146 | set_binary_mode (fd[1], O_TEXT); | - |
| 147 | set_binary_mode (fd[0], O_TEXT); | - |
| 148 | } | - |
| 149 | # endif | - |
| 150 | | - |
| 151 | return 0; never executed: return 0; | 0 |
| 152 | | - |
| 153 | #endif | - |
| 154 | | - |
| 155 | #if GNULIB_defined_O_NONBLOCK || \ | - |
| 156 | !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) | - |
| 157 | fail: | - |
| 158 | { | - |
| 159 | int saved_errno = errno; | - |
| 160 | close (fd[0]); | - |
| 161 | close (fd[1]); | - |
| 162 | fd[0] = tmp[0]; | - |
| 163 | fd[1] = tmp[1]; | - |
| 164 | errno = saved_errno; | - |
| 165 | return -1; never executed: return -1; | 0 |
| 166 | } | - |
| 167 | #endif | - |
| 168 | } | - |
| | |