| 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 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 uint8_t* chars = NULL; | 106 uint8_t* chars = NULL; |
| 107 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 107 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 108 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); | 108 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 109 if (Dart_IsError(result)) { | 109 if (Dart_IsError(result)) { |
| 110 // TODO(turnidge): Consider propagating some errors here. What if | 110 // TODO(turnidge): Consider propagating some errors here. What if |
| 111 // an isolate gets interrupted by the embedder in the middle of | 111 // an isolate gets interrupted by the embedder in the middle of |
| 112 // Dart_StringToUTF8? We need to make sure not to swallow the | 112 // Dart_StringToUTF8? We need to make sure not to swallow the |
| 113 // interrupt. | 113 // interrupt. |
| 114 fprintf(stdout, "%s\n", Dart_GetError(result)); | 114 fprintf(stdout, "%s\n", Dart_GetError(result)); |
| 115 } else { | 115 } else { |
| 116 fprintf(stdout, "%.*s\n", static_cast<int>(length), chars); | 116 // Uses fwrite to support printing NUL bytes. |
| 117 fwrite(chars, 1, length, stdout); |
| 118 fputs("\n", stdout); |
| 117 } | 119 } |
| 118 fflush(stdout); | 120 fflush(stdout); |
| 119 } | 121 } |
| 120 | 122 |
| 121 } // namespace bin | 123 } // namespace bin |
| 122 } // namespace dart | 124 } // namespace dart |
| OLD | NEW |