| 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(HOST_OS_ANDROID) | 6 #if defined(HOST_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
| 9 | 9 |
| 10 #include <signal.h> // NOLINT | 10 #include <signal.h> // NOLINT |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 struct sigaction act; | 29 struct sigaction act; |
| 30 bzero(&act, sizeof(act)); | 30 bzero(&act, sizeof(act)); |
| 31 act.sa_handler = SIG_IGN; | 31 act.sa_handler = SIG_IGN; |
| 32 if (sigaction(SIGPIPE, &act, 0) != 0) { | 32 if (sigaction(SIGPIPE, &act, 0) != 0) { |
| 33 perror("Setting signal handler failed"); | 33 perror("Setting signal handler failed"); |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 | |
| 40 int Platform::NumberOfProcessors() { | 39 int Platform::NumberOfProcessors() { |
| 41 return sysconf(_SC_NPROCESSORS_ONLN); | 40 return sysconf(_SC_NPROCESSORS_ONLN); |
| 42 } | 41 } |
| 43 | 42 |
| 44 | |
| 45 const char* Platform::OperatingSystem() { | 43 const char* Platform::OperatingSystem() { |
| 46 return "android"; | 44 return "android"; |
| 47 } | 45 } |
| 48 | 46 |
| 49 | |
| 50 const char* Platform::LibraryPrefix() { | 47 const char* Platform::LibraryPrefix() { |
| 51 return "lib"; | 48 return "lib"; |
| 52 } | 49 } |
| 53 | 50 |
| 54 | |
| 55 const char* Platform::LibraryExtension() { | 51 const char* Platform::LibraryExtension() { |
| 56 return "so"; | 52 return "so"; |
| 57 } | 53 } |
| 58 | 54 |
| 59 | |
| 60 const char* Platform::LocaleName() { | 55 const char* Platform::LocaleName() { |
| 61 char* lang = getenv("LANG"); | 56 char* lang = getenv("LANG"); |
| 62 if (lang == NULL) { | 57 if (lang == NULL) { |
| 63 return "en_US"; | 58 return "en_US"; |
| 64 } | 59 } |
| 65 return lang; | 60 return lang; |
| 66 } | 61 } |
| 67 | 62 |
| 68 | |
| 69 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { | 63 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { |
| 70 return gethostname(buffer, buffer_length) == 0; | 64 return gethostname(buffer, buffer_length) == 0; |
| 71 } | 65 } |
| 72 | 66 |
| 73 | |
| 74 char** Platform::Environment(intptr_t* count) { | 67 char** Platform::Environment(intptr_t* count) { |
| 75 // Using environ directly is only safe as long as we do not | 68 // Using environ directly is only safe as long as we do not |
| 76 // provide access to modifying environment variables. | 69 // provide access to modifying environment variables. |
| 77 intptr_t i = 0; | 70 intptr_t i = 0; |
| 78 char** tmp = environ; | 71 char** tmp = environ; |
| 79 while (*(tmp++) != NULL) { | 72 while (*(tmp++) != NULL) { |
| 80 i++; | 73 i++; |
| 81 } | 74 } |
| 82 *count = i; | 75 *count = i; |
| 83 char** result; | 76 char** result; |
| 84 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); | 77 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); |
| 85 for (intptr_t current = 0; current < i; current++) { | 78 for (intptr_t current = 0; current < i; current++) { |
| 86 result[current] = environ[current]; | 79 result[current] = environ[current]; |
| 87 } | 80 } |
| 88 return result; | 81 return result; |
| 89 } | 82 } |
| 90 | 83 |
| 91 | |
| 92 const char* Platform::GetExecutableName() { | 84 const char* Platform::GetExecutableName() { |
| 93 return executable_name_; | 85 return executable_name_; |
| 94 } | 86 } |
| 95 | 87 |
| 96 | |
| 97 const char* Platform::ResolveExecutablePath() { | 88 const char* Platform::ResolveExecutablePath() { |
| 98 return NULL; | 89 return NULL; |
| 99 } | 90 } |
| 100 | 91 |
| 101 | |
| 102 void Platform::Exit(int exit_code) { | 92 void Platform::Exit(int exit_code) { |
| 103 exit(exit_code); | 93 exit(exit_code); |
| 104 } | 94 } |
| 105 | 95 |
| 106 } // namespace bin | 96 } // namespace bin |
| 107 } // namespace dart | 97 } // namespace dart |
| 108 | 98 |
| 109 #endif // defined(HOST_OS_ANDROID) | 99 #endif // defined(HOST_OS_ANDROID) |
| OLD | NEW |