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 #ifndef PLATFORM_GLOBALS_H_ | 5 #ifndef PLATFORM_GLOBALS_H_ |
6 #define PLATFORM_GLOBALS_H_ | 6 #define PLATFORM_GLOBALS_H_ |
7 | 7 |
8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
9 // enable platform independent printf format specifiers. | 9 // enable platform independent printf format specifiers. |
10 #ifndef __STDC_FORMAT_MACROS | 10 #ifndef __STDC_FORMAT_MACROS |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 #if defined(_WIN32) | 46 #if defined(_WIN32) |
47 #include "platform/c99_support_win.h" | 47 #include "platform/c99_support_win.h" |
48 #include "platform/inttypes_support_win.h" | 48 #include "platform/inttypes_support_win.h" |
49 #endif | 49 #endif |
50 | 50 |
51 // Target OS detection. | 51 // Target OS detection. |
52 // for more information on predefined macros: | 52 // for more information on predefined macros: |
53 // - http://msdn.microsoft.com/en-us/library/b0084kay.aspx | 53 // - http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
54 // - with gcc, run: "echo | gcc -E -dM -" | 54 // - with gcc, run: "echo | gcc -E -dM -" |
55 #if defined(__linux__) || defined(__FreeBSD__) | 55 #if defined(__ANDROID__) |
| 56 #define TARGET_OS_ANDROID |
| 57 #elif defined(__linux__) || defined(__FreeBSD__) |
56 #define TARGET_OS_LINUX 1 | 58 #define TARGET_OS_LINUX 1 |
57 #elif defined(__APPLE__) | 59 #elif defined(__APPLE__) |
58 #define TARGET_OS_MACOS 1 | 60 #define TARGET_OS_MACOS 1 |
59 #elif defined(_WIN32) | 61 #elif defined(_WIN32) |
60 #define TARGET_OS_WINDOWS 1 | 62 #define TARGET_OS_WINDOWS 1 |
61 #else | 63 #else |
62 #error Automatic target os detection failed. | 64 #error Automatic target os detection failed. |
63 #endif | 65 #endif |
64 | 66 |
65 // Processor architecture detection. For more info on what's defined, see: | 67 // Processor architecture detection. For more info on what's defined, see: |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 sizeof(destination)); | 320 sizeof(destination)); |
319 return destination; | 321 return destination; |
320 } | 322 } |
321 | 323 |
322 | 324 |
323 // A macro to ensure that memcpy cannot be called. memcpy does not handle | 325 // A macro to ensure that memcpy cannot be called. memcpy does not handle |
324 // overlapping memory regions. Even though this is well documented it seems | 326 // overlapping memory regions. Even though this is well documented it seems |
325 // to be used in error quite often. To avoid problems we disallow the direct | 327 // to be used in error quite often. To avoid problems we disallow the direct |
326 // use of memcpy here. | 328 // use of memcpy here. |
327 // | 329 // |
328 // On Windows the basic libraries use memcpy and therefore compilation will | 330 // On Android and Windows the basic libraries use memcpy and therefore |
329 // fail if memcpy is overwritten even if user code does not use memcpy. | 331 // compilation will fail if memcpy is overwritten even if user code does not |
| 332 // use memcpy. |
330 #if defined(memcpy) | 333 #if defined(memcpy) |
331 #undef memcpy | 334 #undef memcpy |
332 #endif | 335 #endif |
333 #if !defined(TARGET_OS_WINDOWS) | 336 #if !( defined(TARGET_OS_ANDROID) || defined(TARGET_OS_WINDOWS) ) |
334 #define memcpy "Please use memmove instead of memcpy." | 337 #define memcpy "Please use memmove instead of memcpy." |
335 #endif | 338 #endif |
336 | 339 |
337 | 340 |
338 // On Windows the reentrent version of strtok is called | 341 // On Windows the reentrent version of strtok is called |
339 // strtok_s. Unify on the posix name strtok_r. | 342 // strtok_s. Unify on the posix name strtok_r. |
340 #if defined(TARGET_OS_WINDOWS) | 343 #if defined(TARGET_OS_WINDOWS) |
341 #define snprintf _snprintf | 344 #define snprintf _snprintf |
342 #define strtok_r strtok_s | 345 #define strtok_r strtok_s |
343 #endif | 346 #endif |
344 | 347 |
345 #if !defined(TARGET_OS_WINDOWS) && !defined(TEMP_FAILURE_RETRY) | 348 #if !defined(TARGET_OS_WINDOWS) && !defined(TEMP_FAILURE_RETRY) |
346 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. The | 349 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. The |
347 // definition below is copied from Linux and adapted to avoid lint | 350 // definition below is copied from Linux and adapted to avoid lint |
348 // errors (type long int changed to int64_t and do/while split on | 351 // errors (type long int changed to int64_t and do/while split on |
349 // separate lines with body in {}s). | 352 // separate lines with body in {}s). |
350 # define TEMP_FAILURE_RETRY(expression) \ | 353 # define TEMP_FAILURE_RETRY(expression) \ |
351 ({ int64_t __result; \ | 354 ({ int64_t __result; \ |
352 do { \ | 355 do { \ |
353 __result = (int64_t) (expression); \ | 356 __result = (int64_t) (expression); \ |
354 } while (__result == -1L && errno == EINTR); \ | 357 } while (__result == -1L && errno == EINTR); \ |
355 __result; }) | 358 __result; }) |
356 #endif | 359 #endif |
357 | 360 |
358 #endif // PLATFORM_GLOBALS_H_ | 361 #endif // PLATFORM_GLOBALS_H_ |
OLD | NEW |