pcsc-lite  1.8.16
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__ && (! defined (__sun)) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
44 #define INTERNAL __attribute__ ((visibility("hidden")))
45 #define PCSC_API __attribute__ ((visibility("default")))
46 #elif (! defined __GNUC__ ) && defined (__sun)
47 /* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */
48 #define INTERNAL __hidden
49 #define PCSC_API __global
50 #else
51 #define INTERNAL
52 #define PCSC_API
53 #endif
54 #define EXTERNAL PCSC_API
55 
56 #if defined __GNUC__
57 
58 /* GNU Compiler Collection (GCC) */
59 #define CONSTRUCTOR __attribute__ ((constructor))
60 #define DESTRUCTOR __attribute__ ((destructor))
61 
62 #else
63 
64 /* SUN C compiler does not use __attribute__ but #pragma init (function)
65  * We can't use a # inside a #define so it is not possible to use
66  * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
67  * The #pragma is used directly where needed */
68 
69 /* any other */
70 #define CONSTRUCTOR
71 #define DESTRUCTOR
72 
73 #endif
74 
75 #ifndef min
76 #define min(a,b) (((a) < (b)) ? (a) : (b))
77 #endif
78 
79 #ifndef COUNT_OF
80 #define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
81 #endif
82 
83 #endif /* __misc_h__ */