36a7bf4d30c2df00898b217138f8d8843a933511
[idzebra-moved-to-github.git] / include / idzebra / util.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef ZEBRA_UTIL_H
21 #define ZEBRA_UTIL_H
22
23 #include <yaz/yconfig.h>
24 #include <yaz/log.h>
25
26 #include <idzebra/version.h>
27
28 /**
29   expand GCC_ATTRIBUTE if GCC is in use. See :
30   http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
31
32   To see gcc pre-defines for c:
33   gcc -E -dM -x c /dev/null
34 */
35
36 #ifdef __GNUC__
37 #if __GNUC__ >= 4
38 #define ZEBRA_GCC_ATTR(x) __attribute__ (x)
39 #endif
40 #endif
41
42 #ifndef ZEBRA_GCC_ATTR
43 #define ZEBRA_GCC_ATTR(x)
44 #endif
45
46 /* check that we don't have all too old yaz */
47 #ifndef YLOG_ERRNO
48 #error Need a modern yaz with YLOG_ defines
49 #endif
50
51 YAZ_BEGIN_CDECL
52
53 /** \var zint
54  * \brief Zebra integer
55  *
56  * This integer is used in various Zebra APIs to specify record identifires,
57  * number of occurrences etc. It is a "large" integer and is usually
58  * 64-bit on newer architectures.
59  */
60 #ifdef WIN32
61 typedef __int64 zint;
62 #define ZINT_FORMAT0 "I64d"
63 #else
64
65 #ifndef ZEBRA_ZINT
66 #error ZEBRA_ZINT undefined. idzebra-config not in use?
67 #endif
68
69 #if ZEBRA_ZINT > 0
70 typedef long long int zint;
71 #define ZINT_FORMAT0 "lld"
72 #else
73 typedef long zint;
74 #define ZINT_FORMAT0 "ld"
75 #endif
76
77 #endif
78
79 #define ZINT_FORMAT "%" ZINT_FORMAT0
80
81 /** \var typedef ZEBRA_RES
82  * \brief Common return type for Zebra API
83  *
84  * This return code indicates success with code ZEBRA_OK and failure
85  * with ZEBRA_FAIL
86  */
87 typedef short ZEBRA_RES;
88 #define ZEBRA_FAIL -1
89 #define ZEBRA_OK   0
90
91 YAZ_EXPORT zint atoi_zn(const char *buf, zint len);
92
93 YAZ_EXPORT void zebra_zint_encode(char **dst, zint pos);
94
95 YAZ_EXPORT void zebra_zint_decode(const char **src, zint *pos);
96
97 YAZ_EXPORT void zebra_exit(const char *msg);
98
99 YAZ_EXPORT zint atozint(const char *src);
100
101 YAZ_END_CDECL
102
103 #define CAST_ZINT_TO_INT(x) (int)(x)
104 #define CAST_ZINT_TO_DOUBLE(x) (double)(x)
105
106 #endif
107 /*
108  * Local variables:
109  * c-basic-offset: 4
110  * c-file-style: "Stroustrup"
111  * indent-tabs-mode: nil
112  * End:
113  * vim: shiftwidth=4 tabstop=8 expandtab
114  */
115