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

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

Issue 11275281: Update dart:io to convert strings between UTF8 and current code page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/platform_macos.cc ('k') | runtime/bin/process_win.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 "bin/platform.h" 5 #include "bin/platform.h"
6 #include "bin/socket.h" 6 #include "bin/socket.h"
7 7
8
9 bool Platform::Initialize() { 8 bool Platform::Initialize() {
10 // Nothing to do on Windows. 9 // Nothing to do on Windows.
11 return true; 10 return true;
12 } 11 }
13 12
14 13
15 int Platform::NumberOfProcessors() { 14 int Platform::NumberOfProcessors() {
16 SYSTEM_INFO info; 15 SYSTEM_INFO info;
17 GetSystemInfo(&info); 16 GetSystemInfo(&info);
18 return info.dwNumberOfProcessors; 17 return info.dwNumberOfProcessors;
(...skipping 10 matching lines...) Expand all
29 if (!socket_initialized) { 28 if (!socket_initialized) {
30 // Initialize Socket for gethostname. 29 // Initialize Socket for gethostname.
31 if (!Socket::Initialize()) return false; 30 if (!Socket::Initialize()) return false;
32 socket_initialized = true; 31 socket_initialized = true;
33 } 32 }
34 return gethostname(buffer, buffer_length) == 0; 33 return gethostname(buffer, buffer_length) == 0;
35 } 34 }
36 35
37 36
38 char** Platform::Environment(intptr_t* count) { 37 char** Platform::Environment(intptr_t* count) {
39 char* strings = GetEnvironmentStringsA(); 38 char* strings = GetEnvironmentStrings();
40 if (strings == NULL) return NULL; 39 if (strings == NULL) return NULL;
41 char* tmp = strings; 40 char* tmp = strings;
42 intptr_t i = 0; 41 intptr_t i = 0;
43 while (*tmp != '\0') { 42 while (*tmp != '\0') {
44 i++; 43 i++;
45 tmp += (strlen(tmp) + 1); 44 tmp += (strlen(tmp) + 1);
46 } 45 }
47 *count = i; 46 *count = i;
48 char** result = new char*[i]; 47 char** result = new char*[i];
48 tmp = strings;
49 for (intptr_t current = 0; current < i; current++) { 49 for (intptr_t current = 0; current < i; current++) {
50 result[current] = strings; 50 result[current] = StringUtils::SystemStringToUtf8(tmp);
51 strings += (strlen(strings) + 1); 51 tmp += (strlen(tmp) + 1);
52 } 52 }
53 FreeEnvironmentStrings(strings);
53 return result; 54 return result;
54 } 55 }
55 56
57 void Platform::FreeEnvironment(char** env, int count) {
58 for (int i = 0; i < count; i++) free(env[i]);
59 delete[] env;
60 }
61
56 62
57 char* Platform::StrError(int error_code) { 63 char* Platform::StrError(int error_code) {
58 static const int kBufferSize = 1024; 64 static const int kBufferSize = 1024;
59 char* error = static_cast<char*>(malloc(kBufferSize)); 65 char* error = static_cast<char*>(malloc(kBufferSize));
60 DWORD message_size = 66 DWORD message_size =
61 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 67 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
62 NULL, 68 NULL,
63 error_code, 69 error_code,
64 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 70 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
65 error, 71 error,
66 kBufferSize, 72 kBufferSize,
67 NULL); 73 NULL);
68 if (message_size == 0) { 74 if (message_size == 0) {
69 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 75 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
70 fprintf(stderr, "FormatMessage failed %d\n", GetLastError()); 76 fprintf(stderr, "FormatMessage failed %d\n", GetLastError());
71 } 77 }
72 snprintf(error, kBufferSize, "OS Error %d", error_code); 78 snprintf(error, kBufferSize, "OS Error %d", error_code);
73 } 79 }
74 // Strip out \r\n at the end of the generated message and ensure 80 // Strip out \r\n at the end of the generated message and ensure
75 // null termination. 81 // null termination.
76 if (message_size > 2 && 82 if (message_size > 2 &&
77 error[message_size - 2] == '\r' && 83 error[message_size - 2] == '\r' &&
78 error[message_size - 1] == '\n') { 84 error[message_size - 1] == '\n') {
79 error[message_size - 2] = '\0'; 85 error[message_size - 2] = '\0';
80 } else { 86 } else {
81 error[kBufferSize - 1] = '\0'; 87 error[kBufferSize - 1] = '\0';
82 } 88 }
83 return error; 89 return error;
84 } 90 }
OLDNEW
« no previous file with comments | « runtime/bin/platform_macos.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698