pcsc-lite  1.8.11
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 Changes to this license can be made only by the copyright author with
22 explicit written consent.
23 
24 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $Id: misc.h 6851 2014-02-14 15:43:32Z rousseau $
36  */
37 
38 #ifndef __misc_h__
39 #define __misc_h__
40 
41 /*
42  * Declare the function as internal to the library: the function name is
43  * not exported and can't be used by a program linked to the library
44  *
45  * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes
46  * see http://www.nedprod.com/programs/gccvisibility.html
47  */
48 #if defined __GNUC__ && (! defined (__sun)) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
49 #define INTERNAL __attribute__ ((visibility("hidden")))
50 #define PCSC_API __attribute__ ((visibility("default")))
51 #elif (! defined __GNUC__ ) && defined (__sun)
52 /* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */
53 #define INTERNAL __hidden
54 #define PCSC_API __global
55 #else
56 #define INTERNAL
57 #define PCSC_API
58 #endif
59 #define EXTERNAL PCSC_API
60 
61 #if defined __GNUC__
62 
63 /* GNU Compiler Collection (GCC) */
64 #define CONSTRUCTOR __attribute__ ((constructor))
65 #define DESTRUCTOR __attribute__ ((destructor))
66 
67 #else
68 
69 /* SUN C compiler does not use __attribute__ but #pragma init (function)
70  * We can't use a # inside a #define so it is not possible to use
71  * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
72  * The #pragma is used directly where needed */
73 
74 /* any other */
75 #define CONSTRUCTOR
76 #define DESTRUCTOR
77 
78 #endif
79 
80 #ifndef min
81 #define min(a,b) (((a) < (b)) ? (a) : (b))
82 #endif
83 
84 #ifndef COUNT_OF
85 #define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
86 #endif
87 
88 #endif /* __misc_h__ */