OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_FUCHSIA) | 6 #if defined(HOST_OS_FUCHSIA) |
7 | 7 |
8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
9 | 9 |
10 #include <magenta/process.h> | 10 #include <magenta/process.h> |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 const char* Platform::executable_name_ = NULL; | 23 const char* Platform::executable_name_ = NULL; |
24 char* Platform::resolved_executable_name_ = NULL; | 24 char* Platform::resolved_executable_name_ = NULL; |
25 int Platform::script_index_ = 1; | 25 int Platform::script_index_ = 1; |
26 char** Platform::argv_ = NULL; | 26 char** Platform::argv_ = NULL; |
27 | 27 |
28 bool Platform::Initialize() { | 28 bool Platform::Initialize() { |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 | |
33 int Platform::NumberOfProcessors() { | 32 int Platform::NumberOfProcessors() { |
34 return sysconf(_SC_NPROCESSORS_CONF); | 33 return sysconf(_SC_NPROCESSORS_CONF); |
35 } | 34 } |
36 | 35 |
37 | |
38 const char* Platform::OperatingSystem() { | 36 const char* Platform::OperatingSystem() { |
39 return "fuchsia"; | 37 return "fuchsia"; |
40 } | 38 } |
41 | 39 |
42 | |
43 const char* Platform::LibraryPrefix() { | 40 const char* Platform::LibraryPrefix() { |
44 return "lib"; | 41 return "lib"; |
45 } | 42 } |
46 | 43 |
47 | |
48 const char* Platform::LibraryExtension() { | 44 const char* Platform::LibraryExtension() { |
49 return "so"; | 45 return "so"; |
50 } | 46 } |
51 | 47 |
52 | |
53 const char* Platform::LocaleName() { | 48 const char* Platform::LocaleName() { |
54 char* lang = getenv("LANG"); | 49 char* lang = getenv("LANG"); |
55 if (lang == NULL) { | 50 if (lang == NULL) { |
56 return "en_US"; | 51 return "en_US"; |
57 } | 52 } |
58 return lang; | 53 return lang; |
59 } | 54 } |
60 | 55 |
61 | |
62 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { | 56 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { |
63 return gethostname(buffer, buffer_length) == 0; | 57 return gethostname(buffer, buffer_length) == 0; |
64 } | 58 } |
65 | 59 |
66 | |
67 char** Platform::Environment(intptr_t* count) { | 60 char** Platform::Environment(intptr_t* count) { |
68 // Using environ directly is only safe as long as we do not | 61 // Using environ directly is only safe as long as we do not |
69 // provide access to modifying environment variables. | 62 // provide access to modifying environment variables. |
70 intptr_t i = 0; | 63 intptr_t i = 0; |
71 char** tmp = environ; | 64 char** tmp = environ; |
72 while (*(tmp++) != NULL) { | 65 while (*(tmp++) != NULL) { |
73 i++; | 66 i++; |
74 } | 67 } |
75 *count = i; | 68 *count = i; |
76 char** result; | 69 char** result; |
77 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); | 70 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); |
78 for (intptr_t current = 0; current < i; current++) { | 71 for (intptr_t current = 0; current < i; current++) { |
79 result[current] = environ[current]; | 72 result[current] = environ[current]; |
80 } | 73 } |
81 return result; | 74 return result; |
82 } | 75 } |
83 | 76 |
84 | |
85 const char* Platform::GetExecutableName() { | 77 const char* Platform::GetExecutableName() { |
86 if (executable_name_ != NULL) { | 78 if (executable_name_ != NULL) { |
87 return executable_name_; | 79 return executable_name_; |
88 } | 80 } |
89 char* name = DartUtils::ScopedCString(MX_MAX_NAME_LEN); | 81 char* name = DartUtils::ScopedCString(MX_MAX_NAME_LEN); |
90 mx_status_t status = mx_object_get_property(mx_process_self(), MX_PROP_NAME, | 82 mx_status_t status = mx_object_get_property(mx_process_self(), MX_PROP_NAME, |
91 name, MX_MAX_NAME_LEN); | 83 name, MX_MAX_NAME_LEN); |
92 if (status != MX_OK) { | 84 if (status != MX_OK) { |
93 return NULL; | 85 return NULL; |
94 } | 86 } |
95 return name; | 87 return name; |
96 } | 88 } |
97 | 89 |
98 | |
99 const char* Platform::ResolveExecutablePath() { | 90 const char* Platform::ResolveExecutablePath() { |
100 const char* executable_name = Platform::GetExecutableName(); | 91 const char* executable_name = Platform::GetExecutableName(); |
101 if (executable_name == NULL) { | 92 if (executable_name == NULL) { |
102 return NULL; | 93 return NULL; |
103 } | 94 } |
104 if ((executable_name[0] == '/') && File::Exists(executable_name)) { | 95 if ((executable_name[0] == '/') && File::Exists(executable_name)) { |
105 return File::GetCanonicalPath(executable_name); | 96 return File::GetCanonicalPath(executable_name); |
106 } | 97 } |
107 if (strchr(executable_name, '/') != NULL) { | 98 if (strchr(executable_name, '/') != NULL) { |
108 const char* result = File::GetCanonicalPath(executable_name); | 99 const char* result = File::GetCanonicalPath(executable_name); |
(...skipping 16 matching lines...) Expand all Loading... |
125 return File::GetCanonicalPath(result); | 116 return File::GetCanonicalPath(result); |
126 } | 117 } |
127 pathcopy = NULL; | 118 pathcopy = NULL; |
128 } | 119 } |
129 } | 120 } |
130 // Couldn't find it. This causes null to be returned for | 121 // Couldn't find it. This causes null to be returned for |
131 // Platform.resovledExecutable. | 122 // Platform.resovledExecutable. |
132 return NULL; | 123 return NULL; |
133 } | 124 } |
134 | 125 |
135 | |
136 void Platform::Exit(int exit_code) { | 126 void Platform::Exit(int exit_code) { |
137 exit(exit_code); | 127 exit(exit_code); |
138 } | 128 } |
139 | 129 |
140 } // namespace bin | 130 } // namespace bin |
141 } // namespace dart | 131 } // namespace dart |
142 | 132 |
143 #endif // defined(HOST_OS_FUCHSIA) | 133 #endif // defined(HOST_OS_FUCHSIA) |
OLD | NEW |