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