-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
99 lines (85 loc) · 2.62 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2006-2009 Jon Kinsey <jonkinsey@gmail.com>
* Copyright (C) 2006-2017 the AUTHORS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* $Id: common.h,v 1.35 2019/12/02 10:56:00 plm Exp $
*/
/*! \file common.h
* \brief Odd definitions
*/
#ifndef COMMON_H
#define COMMON_H
#include <math.h>
#include "config.h"
#ifndef HAVE___ATTRIBUTE__
#define __attribute__(Spec) /* Empty */
#endif /* HAVE___ATTRIBUTE__ */
#define F_PI (float)G_PI
#define F_PI_2 (float)G_PI_2
/*! \brief Safe error value
*/
#if defined(HUGE_VALF)
#define ERR_VAL (-HUGE_VALF)
#else
#define ERR_VAL (-FLT_MAX)
#endif
/*! \brief Macro to extract sign
*/
#ifndef SGN
#define SGN(x) ((x) > 0 ? 1 : -1)
#endif
/*! \brief typedef of signal handler function
*/
#if HAVE_SIGACTION
typedef struct sigaction psighandler;
#elif HAVE_SIGVEC
typedef struct sigvec psighandler;
#else
typedef void (*psighandler) (int);
#endif
/* abs returns unsigned int by definition */
#define Abs(a) ((unsigned int)abs(a))
/* Do we need to use g_utf8_casefold() for utf8 anywhere? */
#define StrCaseCmp(s1, s2) g_ascii_strcasecmp(s1, s2)
#define StrNCaseCmp(s1, s2, n) g_ascii_strncasecmp(s1, s2, (gsize)n)
/* if the following are defined as macros undefine them */
#ifdef strcasecmp
#undef strcasecmp
#endif
#ifdef strncasecmp
#undef strncasecmp
#endif
/* Avoid new code using strcase functions */
#define strcasecmp strcasecmp_error_use_StrCaseCmp
#define strncasecmp strncasecmp_error_use_StrNCaseCmp
/* Macro to mark parameters that aren't used in the function */
#ifdef UNUSED
#elif defined(HAVE_FUNC_ATTRIBUTE_UNUSED)
#define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(_lint)
#define UNUSED(x) /*lint -e{715, 818}*/ _unused_##x
#else
#define UNUSED(x) _unused_##x
#endif
/* Helper macros for __builtin_expect */
#ifdef HAVE___BUILTIN_EXPECT
#define likely(expression) __builtin_expect(!!(expression), 1)
#define unlikely(expression) __builtin_expect(!!(expression), 0)
#else
#define likely(expression) (expression)
#define unlikely(expression) (expression)
#endif
#endif