pcsc-lite 1.9.9
misc.h
1/*
2 * This handles GCC attributes
3 *
4 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
5 *
6 * Copyright (C) 2005-2010
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
183. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef __misc_h__
34#define __misc_h__
35
36/*
37 * Declare the function as internal to the library: the function name is
38 * not exported and can't be used by a program linked to the library
39 *
40 * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes
41 * see http://www.nedprod.com/programs/gccvisibility.html
42 */
43#if defined(__GNUC__) && \
44 (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) || \
45 defined(__SUNPRO_C) && __SUNPRO_C >= 0x590
46#define INTERNAL __attribute__ ((visibility("hidden")))
47#ifndef PCSC_API
48#define PCSC_API __attribute__ ((visibility("default")))
49#endif
50#elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x550
51/* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */
52#define INTERNAL __hidden
53#define PCSC_API __global
54#else
55#define INTERNAL
56#define PCSC_API
57#endif
58#define EXTERNAL PCSC_API
59
60#if defined __GNUC__
61
62/* GNU Compiler Collection (GCC) */
63#define CONSTRUCTOR __attribute__ ((constructor))
64#define DESTRUCTOR __attribute__ ((destructor))
65
66#else
67
68/* SUN C compiler does not use __attribute__ but #pragma init (function)
69 * We can't use a # inside a #define so it is not possible to use
70 * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
71 * The #pragma is used directly where needed */
72
73/* any other */
74#define CONSTRUCTOR
75#define DESTRUCTOR
76
77#endif
78
79#ifndef min
80#define min(a,b) (((a) < (b)) ? (a) : (b))
81#endif
82
83#ifndef COUNT_OF
84#define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
85#endif
86
87#endif /* __misc_h__ */