1
/*
2
 *  Copyright (c) 2009 Nokia Corporation
3
 *  All rights reserved.
4
 * 
5
 *  Redistribution and use in source and binary forms, with or without
6
 *  modification, are permitted provided that the following conditions are
7
 *  met:
8
 * 
9
 *  * Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 *  * Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *  * Neither the name of the Nokia Corporation nor the names of its
15
 *    contributors may be used to endorse or promote products derived from
16
 *    this software without specific prior written permission.
17
 * 
18
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19
 *  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20
 *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21
 *  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22
 *  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 */
31
32
#ifndef __UTILS_H__
33
#define __UTILS_H__
34
35
#ifdef HAVE_CONFIG_H
36
#include "config.h"
37
#endif /*HAVE_CONFIG_H*/
38
39
/*
40
 * TODO: only added the definition for the NOTA_DISABLE_WARNINGS case;
41
 * this should probably be unified with the non-HAVE_ASSERT_H case, which
42
 * good give unwanted results in some cases
43
 */
44
#ifdef NOTA_DISABLE_FATAL_WARNINGS
45
#include <stdio.h>
46
#define nota_assert(COND)                                         \
47
	do {                                                      \
48
	if (!(COND))					          \
49
		fprintf (stderr,                                  \
50
	          "%s: assertion '" #COND "' failed in line %d\n",\
51
		   __FUNCTION__,__LINE__);			  \
52
        }while(0)
53
#else
54
#ifdef HAVE_ASSERT_H
55
#include <assert.h>
56
#define nota_assert(c) assert((c))
57
#else
58
#include <stdio.h>
59
#define nota_assert(c) if(!(c)) {fprintf(stderr, "would have asserted c=%d  file: %s   func: %s   line: %d\n", (int)c,__FILE__, __FUNCTION__, __LINE__);}
60
#endif/*!HAVE_ASSERT_H*/
61
#endif /*NOTA_DISABLE_FATAL_WARNINGS*/
62
63
64
#ifdef HAVE_STDINT_H
65
66
#include <stdint.h>
67
68
#else
69
70
typedef long long unsigned uint64_t;
71
typedef unsigned int       uint32_t;
72
typedef unsigned short     uint16_t;
73
typedef unsigned char      uint8_t;
74
typedef long long int      int64_t;
75
typedef int                int32_t;
76
typedef short              int16_t;
77
typedef char               int8_t;
78
79
#endif
80
81
/*#ifndef boolean_t
82
#define boolean_t int
83
#endif*/
84
85
86
/* byte swapping macros; they won't do anything on little-endian
87
 * machines; these could be optimized by using some asm
88
 */
89
#ifdef BIG_ENDIAN_MACHINE
90
#define nota_swap16b(P) do { *P=(uint16_t) ( \
91
    (uint16_t) ((uint16_t) (*P) >> 8) |  \
92
    (uint16_t) ((uint16_t) (*P) << 8)); } while(0)
93
#else
94
#define nota_swap16b(val) do{}while(0)
95
#endif/*!BIG_ENDIAN_MACHINE*/
96
97
#ifdef BIG_ENDIAN_MACHINE
98
#define nota_swap32b(P) do { (*P)=(uint32_t) (		 \
99
	(((uint32_t) (*P) & (uint32_t) 0x000000ffU) << 24) |	\
100
	(((uint32_t) (*P) & (uint32_t) 0x0000ff00U) <<  8) |	\
101
	(((uint32_t) (*P) & (uint32_t) 0x00ff0000U) >>  8) |	\
102
	(((uint32_t) (*P) & (uint32_t) 0xff000000U) >> 24));}while(0)
103
#else
104
#define nota_swap32b(val) do{}while(0)
105
#endif /*!BIG_ENDIAN_MACHINE*/
106
107
/* inline optimization used as default on various NoTA functions
108
 * in both H_IN & L_IN.
109
 */
110
#ifdef DISABLE_INLINE_OPTIMIZATION
111
#define NOTA_INLINE
112
#else
113
#define NOTA_INLINE inline
114
#endif
115
116
#endif /*__UTILS_H__*/