OLD | NEW |
---|---|
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include <errno.h> | 15 #include <errno.h> |
16 #include <limits.h> | 16 #include <limits.h> |
17 #include <stdio.h> | 17 #include <stdio.h> |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 | 21 |
22 #include <algorithm> | 22 #include <algorithm> |
23 | 23 |
24 int main(int argc, char* argv[]) { | 24 int main(int argc, char* argv[]) { |
25 // Make sure that there’s nothing open at any FD higher than 3. All FDs other | 25 // Make sure that there's nothing open at any FD higher than 3. All FDs other |
Mark Mentovai
2014/12/18 13:46:32
Please don’t do this. If necessary, set your edito
| |
26 // than stdin, stdout, and stderr should have been closed prior to or at | 26 // than stdin, stdout, and stderr should have been closed prior to or at |
27 // exec(). | 27 // exec(). |
28 int max_fd = std::max(static_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX); | 28 int max_fd = std::max(static_cast<int>(sysconf(_SC_OPEN_MAX)), FOPEN_MAX); |
scottmg
2014/12/18 03:53:18
These seems to be quite a bit different on OS X:
Mark Mentovai
2014/12/18 13:46:32
OPEN_MAX and FOPEN_MAX are completely unrelated. T
| |
29 max_fd = std::max(max_fd, getdtablesize()); | 29 max_fd = std::max(max_fd, getdtablesize()); |
30 for (int fd = STDERR_FILENO + 1; fd < max_fd; ++fd) { | 30 for (int fd = STDERR_FILENO + 1; fd < max_fd; ++fd) { |
31 if (close(fd) == 0 || errno != EBADF) { | 31 if (close(fd) == 0 || errno != EBADF) { |
32 abort(); | 32 abort(); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 // Read a byte from stdin, expecting it to be a specific value. | 36 // Read a byte from stdin, expecting it to be a specific value. |
37 char c; | 37 char c; |
38 ssize_t rv = read(STDIN_FILENO, &c, 1); | 38 ssize_t rv = read(STDIN_FILENO, &c, 1); |
39 if (rv != 1 || c != 'z') { | 39 if (rv != 1 || c != 'z') { |
40 abort(); | 40 abort(); |
41 } | 41 } |
42 | 42 |
43 // Write a byte to stdout. | 43 // Write a byte to stdout. |
44 c = 'Z'; | 44 c = 'Z'; |
45 rv = write(STDOUT_FILENO, &c, 1); | 45 rv = write(STDOUT_FILENO, &c, 1); |
46 if (rv != 1) { | 46 if (rv != 1) { |
47 abort(); | 47 abort(); |
48 } | 48 } |
49 | 49 |
50 return 0; | 50 return 0; |
51 } | 51 } |
OLD | NEW |