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

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: Using static bool to control initialization. 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
« no previous file with comments | « runtime/bin/platform_macos.cc ('k') | tests/standalone/src/io/PlatformTest.dart » ('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) 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 // Nothing to do on Windows.
10 return true; 11 return true;
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 static bool socketInitialized = false;
29 if (!socketInitialized) {
30 // Initialize Socket for gethostname.
31 if (!Socket::Initialize()) return false;
32 socketInitialized = true;
33 }
34 return gethostname(buffer, buffer_length) == 0;
35 }
36
37
26 char* Platform::StrError(int error_code) { 38 char* Platform::StrError(int error_code) {
27 static const int kBufferSize = 1024; 39 static const int kBufferSize = 1024;
28 char* error = static_cast<char*>(malloc(kBufferSize)); 40 char* error = static_cast<char*>(malloc(kBufferSize));
29 DWORD message_size = 41 DWORD message_size =
30 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 42 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
31 NULL, 43 NULL,
32 error_code, 44 error_code,
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 45 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
34 error, 46 error,
35 kBufferSize, 47 kBufferSize,
36 NULL); 48 NULL);
37 if (message_size == 0) { 49 if (message_size == 0) {
38 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { 50 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
39 fprintf(stderr, "FormatMessage failed %d\n", GetLastError()); 51 fprintf(stderr, "FormatMessage failed %d\n", GetLastError());
40 } 52 }
41 snprintf(error, kBufferSize, "OS Error %d", error_code); 53 snprintf(error, kBufferSize, "OS Error %d", error_code);
42 } 54 }
43 // Strip out \r\n at the end of the generated message and ensure 55 // Strip out \r\n at the end of the generated message and ensure
44 // null termination. 56 // null termination.
45 if (message_size > 2 && 57 if (message_size > 2 &&
46 error[message_size - 2] == '\r' && 58 error[message_size - 2] == '\r' &&
47 error[message_size - 1] == '\n') { 59 error[message_size - 1] == '\n') {
48 error[message_size - 2] = '\0'; 60 error[message_size - 2] = '\0';
49 } else { 61 } else {
50 error[kBufferSize - 1] = '\0'; 62 error[kBufferSize - 1] = '\0';
51 } 63 }
52 return error; 64 return error;
53 } 65 }
OLDNEW
« no previous file with comments | « runtime/bin/platform_macos.cc ('k') | tests/standalone/src/io/PlatformTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698