port.h (2162B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #ifndef BASE_PORT_H_ 8 #define BASE_PORT_H_ 9 10 #include <stdarg.h> 11 12 #ifdef _MSC_VER 13 # define GG_LONGLONG(x) x##I64 14 # define GG_ULONGLONG(x) x##UI64 15 #else 16 # define GG_LONGLONG(x) x##LL 17 # define GG_ULONGLONG(x) x##ULL 18 #endif 19 20 // Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including <stdint.h> 21 // to get the INTn_C and UINTn_C macros for integer constants. It's difficult 22 // to guarantee any specific ordering of header includes, so it's difficult to 23 // guarantee that the INTn_C macros can be defined by including <stdint.h> at 24 // any specific point. Provide GG_INTn_C macros instead. 25 26 #define GG_INT8_C(x) (x) 27 #define GG_INT16_C(x) (x) 28 #define GG_INT32_C(x) (x) 29 #define GG_INT64_C(x) GG_LONGLONG(x) 30 31 #define GG_UINT8_C(x) (x##U) 32 #define GG_UINT16_C(x) (x##U) 33 #define GG_UINT32_C(x) (x##U) 34 #define GG_UINT64_C(x) GG_ULONGLONG(x) 35 36 namespace base { 37 38 // It's possible for functions that use a va_list, such as StringPrintf, to 39 // invalidate the data in it upon use. The fix is to make a copy of the 40 // structure before using it and use that copy instead. va_copy is provided 41 // for this purpose. MSVC does not provide va_copy, so define an 42 // implementation here. It is not guaranteed that assignment is a copy, so the 43 // StringUtil.VariableArgsFunc unit test tests this capability. 44 45 // The C standard says that va_copy is a "macro", not a function. Trying to 46 // use va_list as ref args to a function, as above, breaks some machines. 47 #if defined(__GNUC__) 48 # define base_va_copy(_a, _b) ::va_copy(_a, _b) 49 #elif defined(_MSC_VER) 50 # define base_va_copy(_a, _b) (_a = _b) 51 #else 52 # error No va_copy for your compiler 53 #endif 54 55 } // namespace base 56 57 // Define an OS-neutral wrapper for shared library entry points 58 #if defined(XP_WIN) 59 # define API_CALL __stdcall 60 #elif defined(XP_LINUX) || defined(XP_DARWIN) 61 # define API_CALL 62 #endif 63 64 #endif // BASE_PORT_H_