ucx
UAP Common Extensions
ucx.h
Go to the documentation of this file.
1 /*
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3  *
4  * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
36 #ifndef UCX_H
37 #define UCX_H
38 
40 #define UCX_VERSION_MAJOR 2
41 
43 #define UCX_VERSION_MINOR 1
44 
46 #define UCX_VERSION (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR)
47 
48 #include <stdlib.h>
49 #include <stdint.h>
50 
51 #ifdef _WIN32
52 #if !(defined __ssize_t_defined || defined _SSIZE_T_)
53 #include <BaseTsd.h>
54 typedef SSIZE_T ssize_t;
55 #define __ssize_t_defined
56 #define _SSIZE_T_
57 #endif /* __ssize_t_defined and _SSIZE_T */
58 #else /* !_WIN32 */
59 #include <sys/types.h>
60 #endif /* _WIN32 */
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 
72 typedef void(*ucx_destructor)(void*);
73 
84 typedef int(*cmp_func)(const void*,const void*,void*);
85 
93 typedef intmax_t(*distance_func)(const void*,const void*,void*);
94 
106 typedef void*(*copy_func)(const void*,void*);
107 
119 typedef size_t(*write_func)(const void*, size_t, size_t, void*);
120 
132 typedef size_t(*read_func)(void*, size_t, size_t, void*);
133 
134 
135 
136 #if __GNUC__ >= 5 || defined(__clang__)
137 #define UCX_MUL_BUILTIN
138 
139 #if __WORDSIZE == 32
140 
152 #define ucx_szmul(a, b, result) __builtin_umul_overflow(a, b, result)
153 #else /* __WORDSIZE != 32 */
154 
166 #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result)
167 #endif /* __WORDSIZE */
168 
169 #else /* no GNUC or clang bultin */
170 
181 #define ucx_szmul(a, b, result) ucx_szmul_impl(a, b, result)
182 
195 int ucx_szmul_impl(size_t a, size_t b, size_t *result);
196 
197 #endif
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* UCX_H */
204 
int(* cmp_func)(const void *, const void *, void *)
Function pointer to a compare function.
Definition: ucx.h:84
size_t(* read_func)(void *, size_t, size_t, void *)
Function pointer to a read function.
Definition: ucx.h:132
intmax_t(* distance_func)(const void *, const void *, void *)
Function pointer to a distance function.
Definition: ucx.h:93
int ucx_szmul_impl(size_t a, size_t b, size_t *result)
Performs a multiplication of size_t values and checks for overflow.
Definition: ucx.c:48
size_t(* write_func)(const void *, size_t, size_t, void *)
Function pointer to a write function.
Definition: ucx.h:119
void(* ucx_destructor)(void *)
A function pointer to a destructor function.
Definition: ucx.h:72