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

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

Issue 10050011: Add member localHostname() to the Dart IO Platform class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 7
7 8
8 bool Platform::Initialize() { 9 bool Platform::Initialize() {
9 // Nothing to do on Windows. 10 // Load Socket for LocalHostname.
Søren Gjesse 2012/04/11 11:00:54 I think we should consider moving this to LocalHos
10 return true; 11 return Socket::Initialize();
Anders Johnsen 2012/04/11 10:12:12 I would like to move the Socket::Initialize setup
11 } 12 }
12 13
13 14
14 int Platform::NumberOfProcessors() { 15 int Platform::NumberOfProcessors() {
15 SYSTEM_INFO info; 16 SYSTEM_INFO info;
16 GetSystemInfo(&info); 17 GetSystemInfo(&info);
17 return info.dwNumberOfProcessors; 18 return info.dwNumberOfProcessors;
18 } 19 }
19 20
20 21
21 const char* Platform::OperatingSystem() { 22 const char* Platform::OperatingSystem() {
22 return "windows"; 23 return "windows";
23 } 24 }
24 25
25 26
27 bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
28 return gethostname(buffer, buffer_length) == 0;
29 }
30
31
26 char* Platform::StrError(int error_code) { 32 char* Platform::StrError(int error_code) {
27 static const int kBufferSize = 1024; 33 static const int kBufferSize = 1024;
28 char* error = static_cast<char*>(malloc(kBufferSize)); 34 char* error = static_cast<char*>(malloc(kBufferSize));
29 DWORD message_size = 35 DWORD message_size =
30 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 36 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
31 NULL, 37 NULL,
32 error_code, 38 error_code,
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 39 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
34 error, 40 error,
35 kBufferSize, 41 kBufferSize,
36 NULL); 42 NULL);
37 if (message_size == 0) { 43 if (message_size == 0) {
38 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 44 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
39 fprintf(stderr, "FormatMessage failed %d\n", GetLastError()); 45 fprintf(stderr, "FormatMessage failed %d\n", GetLastError());
40 } 46 }
41 snprintf(error, kBufferSize, "OS Error %d", error_code); 47 snprintf(error, kBufferSize, "OS Error %d", error_code);
42 } 48 }
43 // Strip out \r\n at the end of the generated message and ensure 49 // Strip out \r\n at the end of the generated message and ensure
44 // null termination. 50 // null termination.
45 if (message_size > 2 && 51 if (message_size > 2 &&
46 error[message_size - 2] == '\r' && 52 error[message_size - 2] == '\r' &&
47 error[message_size - 1] == '\n') { 53 error[message_size - 1] == '\n') {
48 error[message_size - 2] = '\0'; 54 error[message_size - 2] = '\0';
49 } else { 55 } else {
50 error[kBufferSize - 1] = '\0'; 56 error[kBufferSize - 1] = '\0';
51 } 57 }
52 return error; 58 return error;
53 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698