Added function atoizint with a atoi/atoll wrapper.
[idzebra-moved-to-github.git] / include / idzebra / util.h
1 /* $Id: util.h,v 1.13 2006-12-22 13:48:20 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 YAZ_EXPORT zint atoi_zn(const char *buf, zint len);
95
96 YAZ_EXPORT void zebra_zint_encode(char **dst, zint pos);
97
98 YAZ_EXPORT void zebra_zint_decode(const char **src, zint *pos);
99
100 YAZ_EXPORT void zebra_exit(const char *msg);
101
102 typedef struct zebra_timing *zebra_timing_t;
103
104 YAZ_EXPORT
105 zebra_timing_t zebra_timing_create(void);
106 YAZ_EXPORT
107 void zebra_timing_start(zebra_timing_t t);
108 YAZ_EXPORT
109 void zebra_timing_stop(zebra_timing_t t);
110 YAZ_EXPORT
111 double zebra_timing_get_real(zebra_timing_t t);
112 YAZ_EXPORT
113 double zebra_timing_get_user(zebra_timing_t t);
114 YAZ_EXPORT
115 double zebra_timing_get_sys(zebra_timing_t t);
116 YAZ_EXPORT
117 void zebra_timing_destroy(zebra_timing_t *tp);
118
119 YAZ_EXPORT zint atozint(const char *src);
120
121 YAZ_END_CDECL
122
123 #define CAST_ZINT_TO_INT(x) (int)(x)
124 #define CAST_ZINT_TO_DOUBLE(x) (double)(x)
125
126 #endif
127 /*
128  * Local variables:
129  * c-basic-offset: 4
130  * indent-tabs-mode: nil
131  * End:
132  * vim: shiftwidth=4 tabstop=8 expandtab
133  */
134