Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, 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 "bin/platform.h" | 5 #include "bin/platform.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 | 11 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 32 const char* Platform::OperatingSystem() { | 32 const char* Platform::OperatingSystem() { |
| 33 return "linux"; | 33 return "linux"; |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { | 37 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) { |
| 38 return gethostname(buffer, buffer_length) == 0; | 38 return gethostname(buffer, buffer_length) == 0; |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 char** Platform::Environment(intptr_t* count) { | |
| 43 // Using environ directly is only safe as long as we do not | |
| 44 // provide access to modifying environment variables. | |
| 45 intptr_t i = 0; | |
|
Søren Gjesse
2012/04/17 16:10:47
Why add i? Maybe just use *count instead.
Mads Ager (google)
2012/04/17 16:20:14
I wanted to have on clear assignment to count. Als
| |
| 46 char** tmp = environ; | |
| 47 while (*(tmp++) != NULL) i++; | |
| 48 *count = i; | |
| 49 char** result = new char*[i]; | |
| 50 for (intptr_t current = 0; current < i; current++) { | |
| 51 result[current] = environ[current]; | |
| 52 } | |
| 53 return result; | |
| 54 } | |
| 55 | |
| 56 | |
| 42 char* Platform::StrError(int error_code) { | 57 char* Platform::StrError(int error_code) { |
| 43 static const int kBufferSize = 1024; | 58 static const int kBufferSize = 1024; |
| 44 char* error = static_cast<char*>(malloc(kBufferSize)); | 59 char* error = static_cast<char*>(malloc(kBufferSize)); |
| 45 error[0] = '\0'; | 60 error[0] = '\0'; |
| 46 char* error_str = strerror_r(error_code, error, kBufferSize); | 61 char* error_str = strerror_r(error_code, error, kBufferSize); |
| 47 if (error_str != error) { | 62 if (error_str != error) { |
| 48 size_t written = snprintf(error, kBufferSize, "%s", error_str); | 63 size_t written = snprintf(error, kBufferSize, "%s", error_str); |
| 49 ASSERT(written == strlen(error_str)); | 64 ASSERT(written == strlen(error_str)); |
| 50 } | 65 } |
| 51 return error; | 66 return error; |
| 52 } | 67 } |
| OLD | NEW |