pcsc-lite  1.8.23
misc.h
1 /*
2  * This handles GCC attributes
3  *
4  * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
5  *
6  * Copyright (C) 2005-2010
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
13 1. Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 2. 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.
18 3. 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 
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS 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 #define PCSC_API __attribute__ ((visibility("default")))
48 #elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x550
49 /* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */
50 #define INTERNAL __hidden
51 #define PCSC_API __global
52 #else
53 #define INTERNAL
54 #define PCSC_API
55 #endif
56 #define EXTERNAL PCSC_API
57 
58 #if defined __GNUC__
59 
60 /* GNU Compiler Collection (GCC) */
61 #define CONSTRUCTOR __attribute__ ((constructor))
62 #define DESTRUCTOR __attribute__ ((destructor))
63 
64 #else
65 
66 /* SUN C compiler does not use __attribute__ but #pragma init (function)
67  * We can't use a # inside a #define so it is not possible to use
68  * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
69  * The #pragma is used directly where needed */
70 
71 /* any other */
72 #define CONSTRUCTOR
73 #define DESTRUCTOR
74 
75 #endif
76 
77 #ifndef min
78 #define min(a,b) (((a) < (b)) ? (a) : (b))
79 #endif
80 
81 #ifndef COUNT_OF
82 #define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
83 #endif
84 
85 #endif /* __misc_h__ */