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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 #include "bin/platform.h" | 9 #include "bin/platform.h" |
10 | 10 |
11 #include <signal.h> // NOLINT | 11 #include <signal.h> // NOLINT |
12 #include <string.h> // NOLINT | 12 #include <string.h> // NOLINT |
13 #include <unistd.h> // NOLINT | 13 #include <unistd.h> // NOLINT |
14 | 14 |
15 #include "bin/fdutils.h" | 15 #include "bin/fdutils.h" |
16 | 16 |
17 | |
18 namespace dart { | 17 namespace dart { |
19 namespace bin { | 18 namespace bin { |
20 | 19 |
21 bool Platform::Initialize() { | 20 bool Platform::Initialize() { |
22 // Turn off the signal handler for SIGPIPE as it causes the process | 21 // Turn off the signal handler for SIGPIPE as it causes the process |
23 // to terminate on writing to a closed pipe. Without the signal | 22 // to terminate on writing to a closed pipe. Without the signal |
24 // handler error EPIPE is set instead. | 23 // handler error EPIPE is set instead. |
25 struct sigaction act; | 24 struct sigaction act; |
26 bzero(&act, sizeof(act)); | 25 bzero(&act, sizeof(act)); |
27 act.sa_handler = SIG_IGN; | 26 act.sa_handler = SIG_IGN; |
(...skipping 23 matching lines...) Expand all Loading... |
51 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { | 50 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { |
52 return gethostname(buffer, buffer_length) == 0; | 51 return gethostname(buffer, buffer_length) == 0; |
53 } | 52 } |
54 | 53 |
55 | 54 |
56 char** Platform::Environment(intptr_t* count) { | 55 char** Platform::Environment(intptr_t* count) { |
57 // Using environ directly is only safe as long as we do not | 56 // Using environ directly is only safe as long as we do not |
58 // provide access to modifying environment variables. | 57 // provide access to modifying environment variables. |
59 intptr_t i = 0; | 58 intptr_t i = 0; |
60 char** tmp = environ; | 59 char** tmp = environ; |
61 while (*(tmp++) != NULL) i++; | 60 while (*(tmp++) != NULL) { |
| 61 i++; |
| 62 } |
62 *count = i; | 63 *count = i; |
63 char** result = new char*[i]; | 64 char** result; |
| 65 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); |
64 for (intptr_t current = 0; current < i; current++) { | 66 for (intptr_t current = 0; current < i; current++) { |
65 result[current] = environ[current]; | 67 result[current] = environ[current]; |
66 } | 68 } |
67 return result; | 69 return result; |
68 } | 70 } |
69 | 71 |
70 | 72 |
71 void Platform::FreeEnvironment(char** env, intptr_t count) { | 73 const char* Platform::ResolveExecutablePath() { |
72 delete[] env; | 74 return File::LinkTarget("/proc/self/exe"); |
73 } | 75 } |
74 | 76 |
75 | 77 |
76 char* Platform::ResolveExecutablePath() { | |
77 return File::LinkTarget("/proc/self/exe"); | |
78 } | |
79 | |
80 void Platform::Exit(int exit_code) { | 78 void Platform::Exit(int exit_code) { |
81 exit(exit_code); | 79 exit(exit_code); |
82 } | 80 } |
83 | 81 |
84 } // namespace bin | 82 } // namespace bin |
85 } // namespace dart | 83 } // namespace dart |
86 | 84 |
87 #endif // defined(TARGET_OS_LINUX) | 85 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |