OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <errno.h> | 5 #include <errno.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 #include <sys/ioctl.h> | 8 #include <sys/ioctl.h> |
9 | 9 |
10 #include "bin/fdutils.h" | 10 #include "bin/fdutils.h" |
11 | 11 |
12 | 12 |
| 13 bool FDUtils::SetCloseOnExec(intptr_t fd) { |
| 14 intptr_t status; |
| 15 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD)); |
| 16 if (status < 0) { |
| 17 perror("fcntl F_GETFD failed"); |
| 18 return false; |
| 19 } |
| 20 status |= FD_CLOEXEC; |
| 21 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, status)) < 0) { |
| 22 perror("fcntl F_SETFD failed"); |
| 23 return false; |
| 24 } |
| 25 return true; |
| 26 } |
| 27 |
| 28 |
13 static bool SetBlockingHelper(intptr_t fd, bool blocking) { | 29 static bool SetBlockingHelper(intptr_t fd, bool blocking) { |
14 intptr_t status; | 30 intptr_t status; |
15 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 31 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); |
16 if (status < 0) { | 32 if (status < 0) { |
17 perror("fcntl F_GETFL failed"); | 33 perror("fcntl F_GETFL failed"); |
18 return false; | 34 return false; |
19 } | 35 } |
20 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); | 36 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); |
21 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { | 37 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { |
22 perror("fcntl F_SETFL failed"); | 38 perror("fcntl F_SETFL failed"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 ASSERT(errno != EWOULDBLOCK); | 126 ASSERT(errno != EWOULDBLOCK); |
111 return -1; | 127 return -1; |
112 } else { | 128 } else { |
113 ASSERT(bytes_written > 0); | 129 ASSERT(bytes_written > 0); |
114 remaining -= bytes_written; | 130 remaining -= bytes_written; |
115 buffer_pos += bytes_written; | 131 buffer_pos += bytes_written; |
116 } | 132 } |
117 } | 133 } |
118 return count; | 134 return count; |
119 } | 135 } |
OLD | NEW |