15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_PORT_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_PORT_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdarg.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef COMPILER_MSVC 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_LONGLONG(x) x##I64 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_ULONGLONG(x) x##UI64 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_LONGLONG(x) x##LL 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_ULONGLONG(x) x##ULL 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including <stdint.h> 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to get the INTn_C and UINTn_C macros for integer constants. It's difficult 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to guarantee any specific ordering of header includes, so it's difficult to 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// guarantee that the INTn_C macros can be defined by including <stdint.h> at 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// any specific point. Provide GG_INTn_C macros instead. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_INT8_C(x) (x) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_INT16_C(x) (x) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_INT32_C(x) (x) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_INT64_C(x) GG_LONGLONG(x) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_UINT8_C(x) (x ## U) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_UINT16_C(x) (x ## U) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_UINT32_C(x) (x ## U) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_UINT64_C(x) GG_ULONGLONG(x) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// It's possible for functions that use a va_list, such as StringPrintf, to 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// invalidate the data in it upon use. The fix is to make a copy of the 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// structure before using it and use that copy instead. va_copy is provided 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for this purpose. MSVC does not provide va_copy, so define an 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// implementation here. It is not guaranteed that assignment is a copy, so the 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// StringUtil.VariableArgsFunc unit test tests this capability. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(COMPILER_GCC) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_VA_COPY(a, b) (va_copy(a, b)) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(COMPILER_MSVC) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define GG_VA_COPY(a, b) (a = b) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Define an OS-neutral wrapper for shared library entry points 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define API_CALL __stdcall 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define API_CALL 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // BASE_PORT_H_ 55