Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: runtime/bin/platform_linux.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/platform_fuchsia.cc ('k') | runtime/bin/platform_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_LINUX) 6 #if defined(HOST_OS_LINUX)
7 7
8 #include "bin/platform.h" 8 #include "bin/platform.h"
9 9
10 #include <signal.h> // NOLINT 10 #include <signal.h> // NOLINT
11 #include <string.h> // NOLINT 11 #include <string.h> // NOLINT
12 #include <unistd.h> // NOLINT 12 #include <unistd.h> // NOLINT
13 13
14 #include "bin/fdutils.h" 14 #include "bin/fdutils.h"
15 #include "bin/file.h" 15 #include "bin/file.h"
16 16
17 namespace dart { 17 namespace dart {
18 namespace bin { 18 namespace bin {
19 19
20 const char* Platform::executable_name_ = NULL; 20 const char* Platform::executable_name_ = NULL;
21 char* Platform::resolved_executable_name_ = NULL; 21 char* Platform::resolved_executable_name_ = NULL;
22 int Platform::script_index_ = 1; 22 int Platform::script_index_ = 1;
23 char** Platform::argv_ = NULL; 23 char** Platform::argv_ = NULL;
24 24
25 static void segv_handler(int signal, siginfo_t* siginfo, void* context) { 25 static void segv_handler(int signal, siginfo_t* siginfo, void* context) {
26 Dart_DumpNativeStackTrace(context); 26 Dart_DumpNativeStackTrace(context);
27 abort(); 27 abort();
28 } 28 }
29 29
30
31 bool Platform::Initialize() { 30 bool Platform::Initialize() {
32 // Turn off the signal handler for SIGPIPE as it causes the process 31 // Turn off the signal handler for SIGPIPE as it causes the process
33 // to terminate on writing to a closed pipe. Without the signal 32 // to terminate on writing to a closed pipe. Without the signal
34 // handler error EPIPE is set instead. 33 // handler error EPIPE is set instead.
35 struct sigaction act; 34 struct sigaction act;
36 bzero(&act, sizeof(act)); 35 bzero(&act, sizeof(act));
37 act.sa_handler = SIG_IGN; 36 act.sa_handler = SIG_IGN;
38 if (sigaction(SIGPIPE, &act, 0) != 0) { 37 if (sigaction(SIGPIPE, &act, 0) != 0) {
39 perror("Setting signal handler failed"); 38 perror("Setting signal handler failed");
40 return false; 39 return false;
(...skipping 13 matching lines...) Expand all
54 perror("sigaction() failed."); 53 perror("sigaction() failed.");
55 return false; 54 return false;
56 } 55 }
57 if (sigaction(SIGTRAP, &act, NULL) != 0) { 56 if (sigaction(SIGTRAP, &act, NULL) != 0) {
58 perror("sigaction() failed."); 57 perror("sigaction() failed.");
59 return false; 58 return false;
60 } 59 }
61 return true; 60 return true;
62 } 61 }
63 62
64
65 int Platform::NumberOfProcessors() { 63 int Platform::NumberOfProcessors() {
66 return sysconf(_SC_NPROCESSORS_ONLN); 64 return sysconf(_SC_NPROCESSORS_ONLN);
67 } 65 }
68 66
69
70 const char* Platform::OperatingSystem() { 67 const char* Platform::OperatingSystem() {
71 return "linux"; 68 return "linux";
72 } 69 }
73 70
74
75 const char* Platform::LibraryPrefix() { 71 const char* Platform::LibraryPrefix() {
76 return "lib"; 72 return "lib";
77 } 73 }
78 74
79
80 const char* Platform::LibraryExtension() { 75 const char* Platform::LibraryExtension() {
81 return "so"; 76 return "so";
82 } 77 }
83 78
84
85 const char* Platform::LocaleName() { 79 const char* Platform::LocaleName() {
86 char* lang = getenv("LANG"); 80 char* lang = getenv("LANG");
87 if (lang == NULL) { 81 if (lang == NULL) {
88 return "en_US"; 82 return "en_US";
89 } 83 }
90 return lang; 84 return lang;
91 } 85 }
92 86
93
94 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) { 87 bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
95 return gethostname(buffer, buffer_length) == 0; 88 return gethostname(buffer, buffer_length) == 0;
96 } 89 }
97 90
98
99 char** Platform::Environment(intptr_t* count) { 91 char** Platform::Environment(intptr_t* count) {
100 // Using environ directly is only safe as long as we do not 92 // Using environ directly is only safe as long as we do not
101 // provide access to modifying environment variables. 93 // provide access to modifying environment variables.
102 intptr_t i = 0; 94 intptr_t i = 0;
103 char** tmp = environ; 95 char** tmp = environ;
104 while (*(tmp++) != NULL) { 96 while (*(tmp++) != NULL) {
105 i++; 97 i++;
106 } 98 }
107 *count = i; 99 *count = i;
108 char** result; 100 char** result;
109 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result))); 101 result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result)));
110 for (intptr_t current = 0; current < i; current++) { 102 for (intptr_t current = 0; current < i; current++) {
111 result[current] = environ[current]; 103 result[current] = environ[current];
112 } 104 }
113 return result; 105 return result;
114 } 106 }
115 107
116
117 const char* Platform::GetExecutableName() { 108 const char* Platform::GetExecutableName() {
118 return executable_name_; 109 return executable_name_;
119 } 110 }
120 111
121
122 const char* Platform::ResolveExecutablePath() { 112 const char* Platform::ResolveExecutablePath() {
123 return File::LinkTarget("/proc/self/exe"); 113 return File::LinkTarget("/proc/self/exe");
124 } 114 }
125 115
126
127 void Platform::Exit(int exit_code) { 116 void Platform::Exit(int exit_code) {
128 exit(exit_code); 117 exit(exit_code);
129 } 118 }
130 119
131 } // namespace bin 120 } // namespace bin
132 } // namespace dart 121 } // namespace dart
133 122
134 #endif // defined(HOST_OS_LINUX) 123 #endif // defined(HOST_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/platform_fuchsia.cc ('k') | runtime/bin/platform_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698