| OLD | NEW |
| 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "bin/platform.h" | 7 #include "bin/platform.h" |
| 8 | 8 |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
| 11 #include "include/dart_api.h" | 11 #include "include/dart_api.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 namespace bin { | 14 namespace bin { |
| 15 | 15 |
| 16 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { | 16 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { |
| 17 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); | 17 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | |
| 21 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { | 20 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { |
| 22 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); | 21 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); |
| 23 } | 22 } |
| 24 | 23 |
| 25 | |
| 26 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { | 24 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { |
| 27 Dart_SetReturnValue(args, DartUtils::NewString(File::PathSeparator())); | 25 Dart_SetReturnValue(args, DartUtils::NewString(File::PathSeparator())); |
| 28 } | 26 } |
| 29 | 27 |
| 30 | |
| 31 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { | 28 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { |
| 32 const intptr_t HOSTNAME_LENGTH = 256; | 29 const intptr_t HOSTNAME_LENGTH = 256; |
| 33 char hostname[HOSTNAME_LENGTH]; | 30 char hostname[HOSTNAME_LENGTH]; |
| 34 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { | 31 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { |
| 35 Dart_SetReturnValue(args, DartUtils::NewString(hostname)); | 32 Dart_SetReturnValue(args, DartUtils::NewString(hostname)); |
| 36 } else { | 33 } else { |
| 37 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 34 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 38 } | 35 } |
| 39 } | 36 } |
| 40 | 37 |
| 41 | |
| 42 void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) { | 38 void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) { |
| 43 if (Platform::GetExecutableName() != NULL) { | 39 if (Platform::GetExecutableName() != NULL) { |
| 44 Dart_SetReturnValue( | 40 Dart_SetReturnValue( |
| 45 args, Dart_NewStringFromCString(Platform::GetExecutableName())); | 41 args, Dart_NewStringFromCString(Platform::GetExecutableName())); |
| 46 } else { | 42 } else { |
| 47 Dart_SetReturnValue(args, Dart_Null()); | 43 Dart_SetReturnValue(args, Dart_Null()); |
| 48 } | 44 } |
| 49 } | 45 } |
| 50 | 46 |
| 51 | |
| 52 void FUNCTION_NAME(Platform_ResolvedExecutableName)(Dart_NativeArguments args) { | 47 void FUNCTION_NAME(Platform_ResolvedExecutableName)(Dart_NativeArguments args) { |
| 53 if (Platform::GetResolvedExecutableName() != NULL) { | 48 if (Platform::GetResolvedExecutableName() != NULL) { |
| 54 Dart_SetReturnValue( | 49 Dart_SetReturnValue( |
| 55 args, Dart_NewStringFromCString(Platform::GetResolvedExecutableName())); | 50 args, Dart_NewStringFromCString(Platform::GetResolvedExecutableName())); |
| 56 } else { | 51 } else { |
| 57 Dart_SetReturnValue(args, Dart_Null()); | 52 Dart_SetReturnValue(args, Dart_Null()); |
| 58 } | 53 } |
| 59 } | 54 } |
| 60 | 55 |
| 61 | |
| 62 void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) { | 56 void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) { |
| 63 int end = Platform::GetScriptIndex(); | 57 int end = Platform::GetScriptIndex(); |
| 64 char** argv = Platform::GetArgv(); | 58 char** argv = Platform::GetArgv(); |
| 65 Dart_Handle result = Dart_NewList(end - 1); | 59 Dart_Handle result = Dart_NewList(end - 1); |
| 66 for (intptr_t i = 1; i < end; i++) { | 60 for (intptr_t i = 1; i < end; i++) { |
| 67 Dart_Handle str = DartUtils::NewString(argv[i]); | 61 Dart_Handle str = DartUtils::NewString(argv[i]); |
| 68 Dart_Handle error = Dart_ListSetAt(result, i - 1, str); | 62 Dart_Handle error = Dart_ListSetAt(result, i - 1, str); |
| 69 if (Dart_IsError(error)) { | 63 if (Dart_IsError(error)) { |
| 70 Dart_PropagateError(error); | 64 Dart_PropagateError(error); |
| 71 } | 65 } |
| 72 } | 66 } |
| 73 Dart_SetReturnValue(args, result); | 67 Dart_SetReturnValue(args, result); |
| 74 } | 68 } |
| 75 | 69 |
| 76 | |
| 77 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { | 70 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { |
| 78 intptr_t count = 0; | 71 intptr_t count = 0; |
| 79 char** env = Platform::Environment(&count); | 72 char** env = Platform::Environment(&count); |
| 80 if (env == NULL) { | 73 if (env == NULL) { |
| 81 OSError error(-1, "Failed to retrieve environment variables.", | 74 OSError error(-1, "Failed to retrieve environment variables.", |
| 82 OSError::kUnknown); | 75 OSError::kUnknown); |
| 83 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 76 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
| 84 } else { | 77 } else { |
| 85 Dart_Handle result = Dart_NewList(count); | 78 Dart_Handle result = Dart_NewList(count); |
| 86 if (Dart_IsError(result)) { | 79 if (Dart_IsError(result)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 Dart_Handle error = Dart_ListSetAt(result, result_idx, str); | 90 Dart_Handle error = Dart_ListSetAt(result, result_idx, str); |
| 98 if (Dart_IsError(error)) { | 91 if (Dart_IsError(error)) { |
| 99 Dart_PropagateError(error); | 92 Dart_PropagateError(error); |
| 100 } | 93 } |
| 101 result_idx++; | 94 result_idx++; |
| 102 } | 95 } |
| 103 Dart_SetReturnValue(args, result); | 96 Dart_SetReturnValue(args, result); |
| 104 } | 97 } |
| 105 } | 98 } |
| 106 | 99 |
| 107 | |
| 108 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { | 100 void FUNCTION_NAME(Platform_GetVersion)(Dart_NativeArguments args) { |
| 109 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); | 101 Dart_SetReturnValue(args, Dart_NewStringFromCString(Dart_VersionString())); |
| 110 } | 102 } |
| 111 | 103 |
| 112 | |
| 113 void FUNCTION_NAME(Platform_LocaleName)(Dart_NativeArguments args) { | 104 void FUNCTION_NAME(Platform_LocaleName)(Dart_NativeArguments args) { |
| 114 const char* locale = Platform::LocaleName(); | 105 const char* locale = Platform::LocaleName(); |
| 115 if (locale == NULL) { | 106 if (locale == NULL) { |
| 116 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 107 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 117 } else { | 108 } else { |
| 118 Dart_SetReturnValue(args, Dart_NewStringFromCString(locale)); | 109 Dart_SetReturnValue(args, Dart_NewStringFromCString(locale)); |
| 119 } | 110 } |
| 120 } | 111 } |
| 121 | 112 |
| 122 } // namespace bin | 113 } // namespace bin |
| 123 } // namespace dart | 114 } // namespace dart |
| 124 | 115 |
| 125 #endif // !defined(DART_IO_DISABLED) | 116 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |