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

Side by Side Diff: runtime/vm/os_macos.cc

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add missing include Created 5 years, 3 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
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_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 "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { 208 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
209 int retval = vsnprintf(str, size, format, args); 209 int retval = vsnprintf(str, size, format, args);
210 if (retval < 0) { 210 if (retval < 0) {
211 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); 211 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
212 } 212 }
213 return retval; 213 return retval;
214 } 214 }
215 215
216 216
217 char* OS::SCreate(Zone* zone, const char* format, ...) {
218 va_list args;
219 va_start(args, format);
220 char* buffer = VSCreate(zone, format, args);
221 va_end(args);
222 return buffer;
223 }
224
225
226 char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
227 // Measure.
228 va_list measure_args;
229 va_copy(measure_args, args);
230 intptr_t len = VSNPrint(NULL, 0, format, measure_args);
231 va_end(measure_args);
232
233 char* buffer;
234 if (zone) {
235 buffer = zone->Alloc<char>(len + 1);
236 } else {
237 buffer = reinterpret_cast<char*>(malloc(len + 1));
238 }
239 ASSERT(buffer != NULL);
240
241 // Print.
242 va_list print_args;
243 va_copy(print_args, args);
244 VSNPrint(buffer, len + 1, format, print_args);
245 va_end(print_args);
246 return buffer;
247 }
248
249
217 bool OS::StringToInt64(const char* str, int64_t* value) { 250 bool OS::StringToInt64(const char* str, int64_t* value) {
218 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); 251 ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
219 int32_t base = 10; 252 int32_t base = 10;
220 char* endptr; 253 char* endptr;
221 int i = 0; 254 int i = 0;
222 if (str[0] == '-') { 255 if (str[0] == '-') {
223 i = 1; 256 i = 1;
224 } 257 }
225 if ((str[i] == '0') && 258 if ((str[i] == '0') &&
226 (str[i + 1] == 'x' || str[i + 1] == 'X') && 259 (str[i + 1] == 'x' || str[i + 1] == 'X') &&
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 297 }
265 298
266 299
267 void OS::Exit(int code) { 300 void OS::Exit(int code) {
268 exit(code); 301 exit(code);
269 } 302 }
270 303
271 } // namespace dart 304 } // namespace dart
272 305
273 #endif // defined(TARGET_OS_MACOS) 306 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698