Blame src/misc.h

Packit 9f0df5
/*
Packit 9f0df5
 * This handles GCC attributes
Packit 9f0df5
 *
Packit 9f0df5
 * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
Packit 9f0df5
 *
Packit 9f0df5
 * Copyright (C) 2005-2010
Packit 9f0df5
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
Packit 9f0df5
 *
Packit 9f0df5
Redistribution and use in source and binary forms, with or without
Packit 9f0df5
modification, are permitted provided that the following conditions
Packit 9f0df5
are met:
Packit 9f0df5
Packit 9f0df5
1. Redistributions of source code must retain the above copyright
Packit 9f0df5
   notice, this list of conditions and the following disclaimer.
Packit 9f0df5
2. Redistributions in binary form must reproduce the above copyright
Packit 9f0df5
   notice, this list of conditions and the following disclaimer in the
Packit 9f0df5
   documentation and/or other materials provided with the distribution.
Packit 9f0df5
3. The name of the author may not be used to endorse or promote products
Packit 9f0df5
   derived from this software without specific prior written permission.
Packit 9f0df5
Packit 9f0df5
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit 9f0df5
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 9f0df5
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit 9f0df5
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 9f0df5
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit 9f0df5
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 9f0df5
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 9f0df5
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 9f0df5
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit 9f0df5
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 9f0df5
 */
Packit 9f0df5
Packit 9f0df5
#ifndef __misc_h__
Packit 9f0df5
#define __misc_h__
Packit 9f0df5
Packit 9f0df5
/*
Packit 9f0df5
 * Declare the function as internal to the library: the function name is
Packit 9f0df5
 * not exported and can't be used by a program linked to the library
Packit 9f0df5
 *
Packit 9f0df5
 * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes
Packit 9f0df5
 * see http://www.nedprod.com/programs/gccvisibility.html
Packit 9f0df5
 */
Packit 9f0df5
#if defined(__GNUC__) && \
Packit 9f0df5
	(__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) || \
Packit 9f0df5
	defined(__SUNPRO_C) && __SUNPRO_C >= 0x590
Packit 9f0df5
#define INTERNAL __attribute__ ((visibility("hidden")))
Packit 9f0df5
#define PCSC_API __attribute__ ((visibility("default")))
Packit 9f0df5
#elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x550
Packit 9f0df5
/* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */
Packit 9f0df5
#define INTERNAL __hidden
Packit 9f0df5
#define PCSC_API __global
Packit 9f0df5
#else
Packit 9f0df5
#define INTERNAL
Packit 9f0df5
#define PCSC_API
Packit 9f0df5
#endif
Packit 9f0df5
#define EXTERNAL PCSC_API
Packit 9f0df5
Packit 9f0df5
#if defined __GNUC__
Packit 9f0df5
Packit 9f0df5
/* GNU Compiler Collection (GCC) */
Packit 9f0df5
#define CONSTRUCTOR __attribute__ ((constructor))
Packit 9f0df5
#define DESTRUCTOR __attribute__ ((destructor))
Packit 9f0df5
Packit 9f0df5
#else
Packit 9f0df5
Packit 9f0df5
/* SUN C compiler does not use __attribute__ but #pragma init (function)
Packit 9f0df5
 * We can't use a # inside a #define so it is not possible to use
Packit 9f0df5
 * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
Packit 9f0df5
 * The #pragma is used directly where needed */
Packit 9f0df5
Packit 9f0df5
/* any other */
Packit 9f0df5
#define CONSTRUCTOR
Packit 9f0df5
#define DESTRUCTOR
Packit 9f0df5
Packit 9f0df5
#endif
Packit 9f0df5
Packit 9f0df5
#ifndef min
Packit 9f0df5
#define min(a,b) (((a) < (b)) ? (a) : (b))
Packit 9f0df5
#endif
Packit 9f0df5
Packit 9f0df5
#ifndef COUNT_OF
Packit 9f0df5
#define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
Packit 9f0df5
#endif
Packit 9f0df5
Packit 9f0df5
#endif /* __misc_h__ */