Sun, 29 Dec 2019 16:04:34 +0100
adds more sstrreplace tests
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
1 | /* |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
3 | * |
259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
27 | */ |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
94
diff
changeset
|
28 | |
251
fae240d633fc
changes source directory structure in preperation for autotools rollout
Mike Becker <universe@uap-core.de>
parents:
250
diff
changeset
|
29 | #include "ucx/utils.h" |
fae240d633fc
changes source directory structure in preperation for autotools rollout
Mike Becker <universe@uap-core.de>
parents:
250
diff
changeset
|
30 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
31 | #include <math.h> |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
32 | #include <stdio.h> |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
33 | #include <limits.h> |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
34 | #include <errno.h> |
89 | 35 | |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
36 | /* COPY FUCNTIONS */ |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
37 | void* ucx_strcpy(const void* s, void* data) { |
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
38 | const char *str = (const char*) s; |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
39 | size_t n = 1+strlen(str); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
40 | char *cpy = (char*) malloc(n); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
41 | memcpy(cpy, str, n); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
42 | return cpy; |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
43 | } |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
44 | |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
45 | void* ucx_memcpy(const void* m, void* n) { |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
46 | size_t k = *((size_t*)n); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
47 | void *cpy = malloc(k); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
48 | memcpy(cpy, m, k); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
49 | return cpy; |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
50 | } |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
51 | |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
52 | size_t ucx_stream_bncopy(void *src, void *dest, read_func readfnc, |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
53 | write_func writefnc, char* buf, size_t bufsize, size_t n) { |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
54 | if(n == 0 || bufsize == 0) { |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
55 | return 0; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
56 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
57 | |
181
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
58 | char *lbuf; |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
59 | size_t ncp = 0; |
181
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
60 | |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
61 | if(buf) { |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
62 | lbuf = buf; |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
63 | } else { |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
64 | lbuf = (char*)malloc(bufsize); |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
65 | if(lbuf == NULL) { |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
66 | return 0; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
67 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
68 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
69 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
70 | size_t r; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
71 | size_t rn = bufsize > n ? n : bufsize; |
181
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
72 | while((r = readfnc(lbuf, 1, rn, src)) != 0) { |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
73 | r = writefnc(lbuf, 1, r, dest); |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
74 | ncp += r; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
75 | n -= r; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
76 | rn = bufsize > n ? n : bufsize; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
77 | if(r == 0 || n == 0) { |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
78 | break; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
79 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
80 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
81 | |
181
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
82 | if (lbuf != buf) { |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
83 | free(lbuf); |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
84 | } |
1e9012ad8215
fixed stream copy bug + fixed doc issues in mempool
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
85 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
86 | return ncp; |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
87 | } |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
88 | |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
89 | /* COMPARE FUNCTIONS */ |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
90 | |
308
d6f580621512
renames ucx_strcmp() to ucx_cmp_str()
Mike Becker <universe@uap-core.de>
parents:
292
diff
changeset
|
91 | int ucx_cmp_str(const void *s1, const void *s2, void *data) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
92 | return strcmp((const char*)s1, (const char*)s2); |
89 | 93 | } |
94 | ||
309
4355c6039a28
renames ucx_strncmp() to ucx_cmp_strn()
Mike Becker <universe@uap-core.de>
parents:
308
diff
changeset
|
95 | int ucx_cmp_strn(const void *s1, const void *s2, void *n) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
96 | return strncmp((const char*)s1, (const char*)s2, *((size_t*) n)); |
89 | 97 | } |
98 | ||
310
b09677d72413
renames ucx_sstrcmp() to ucx_cmp_sstr()
Mike Becker <universe@uap-core.de>
parents:
309
diff
changeset
|
99 | int ucx_cmp_sstr(const void *s1, const void *s2, void *data) { |
292
d9abf53b8397
adds ucx_sstrcmp() compare function to utils.h
Mike Becker <universe@uap-core.de>
parents:
286
diff
changeset
|
100 | sstr_t a = *(const sstr_t*) s1; |
d9abf53b8397
adds ucx_sstrcmp() compare function to utils.h
Mike Becker <universe@uap-core.de>
parents:
286
diff
changeset
|
101 | sstr_t b = *(const sstr_t*) s2; |
d9abf53b8397
adds ucx_sstrcmp() compare function to utils.h
Mike Becker <universe@uap-core.de>
parents:
286
diff
changeset
|
102 | return sstrcmp(a, b); |
d9abf53b8397
adds ucx_sstrcmp() compare function to utils.h
Mike Becker <universe@uap-core.de>
parents:
286
diff
changeset
|
103 | } |
d9abf53b8397
adds ucx_sstrcmp() compare function to utils.h
Mike Becker <universe@uap-core.de>
parents:
286
diff
changeset
|
104 | |
314
5d28dc8f0765
renames int and longint distance and compare functions according to the new scheme
Mike Becker <universe@uap-core.de>
parents:
313
diff
changeset
|
105 | int ucx_cmp_int(const void *i1, const void *i2, void *data) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
106 | int a = *((const int*) i1); |
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
107 | int b = *((const int*) i2); |
89 | 108 | if (a == b) { |
109 | return 0; | |
110 | } else { | |
111 | return a < b ? -1 : 1; | |
112 | } | |
113 | } | |
114 | ||
314
5d28dc8f0765
renames int and longint distance and compare functions according to the new scheme
Mike Becker <universe@uap-core.de>
parents:
313
diff
changeset
|
115 | int ucx_cmp_longint(const void *i1, const void *i2, void *data) { |
349
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
116 | long int a = *((const long int*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
117 | long int b = *((const long int*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
118 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
119 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
120 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
121 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
122 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
123 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
124 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
125 | int ucx_cmp_longlong(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
126 | long long a = *((const long long*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
127 | long long b = *((const long long*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
128 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
129 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
130 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
131 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
132 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
133 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
134 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
135 | int ucx_cmp_int16(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
136 | int16_t a = *((const int16_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
137 | int16_t b = *((const int16_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
138 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
139 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
140 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
141 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
142 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
143 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
144 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
145 | int ucx_cmp_int32(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
146 | int32_t a = *((const int32_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
147 | int32_t b = *((const int32_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
148 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
149 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
150 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
151 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
152 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
153 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
154 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
155 | int ucx_cmp_int64(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
156 | int64_t a = *((const int64_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
157 | int64_t b = *((const int64_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
158 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
159 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
160 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
161 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
162 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
163 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
164 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
165 | int ucx_cmp_uint(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
166 | unsigned int a = *((const unsigned int*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
167 | unsigned int b = *((const unsigned int*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
168 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
169 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
170 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
171 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
172 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
173 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
174 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
175 | int ucx_cmp_ulongint(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
176 | unsigned long int a = *((const unsigned long int*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
177 | unsigned long int b = *((const unsigned long int*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
178 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
179 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
180 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
181 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
182 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
183 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
184 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
185 | int ucx_cmp_ulonglong(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
186 | unsigned long long a = *((const unsigned long long*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
187 | unsigned long long b = *((const unsigned long long*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
188 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
189 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
190 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
191 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
192 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
193 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
194 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
195 | int ucx_cmp_uint16(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
196 | uint16_t a = *((const uint16_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
197 | uint16_t b = *((const uint16_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
198 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
199 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
200 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
201 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
202 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
203 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
204 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
205 | int ucx_cmp_uint32(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
206 | uint32_t a = *((const uint32_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
207 | uint32_t b = *((const uint32_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
208 | if (a == b) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
209 | return 0; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
210 | } else { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
211 | return a < b ? -1 : 1; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
212 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
213 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
214 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
215 | int ucx_cmp_uint64(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
216 | uint64_t a = *((const uint64_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
217 | uint64_t b = *((const uint64_t*) i2); |
285
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
218 | if (a == b) { |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
219 | return 0; |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
220 | } else { |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
221 | return a < b ? -1 : 1; |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
222 | } |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
223 | } |
7be3ae7ffb58
adds ucx_longintcmp() compare function
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
224 | |
314
5d28dc8f0765
renames int and longint distance and compare functions according to the new scheme
Mike Becker <universe@uap-core.de>
parents:
313
diff
changeset
|
225 | intmax_t ucx_dist_int(const void *i1, const void *i2, void *data) { |
286
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
226 | intmax_t a = *((const int*) i1); |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
227 | intmax_t b = *((const int*) i2); |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
228 | return a - b; |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
229 | } |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
230 | |
314
5d28dc8f0765
renames int and longint distance and compare functions according to the new scheme
Mike Becker <universe@uap-core.de>
parents:
313
diff
changeset
|
231 | intmax_t ucx_dist_longint(const void *i1, const void *i2, void *data) { |
286
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
232 | intmax_t a = *((const long int*) i1); |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
233 | intmax_t b = *((const long int*) i2); |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
234 | return a - b; |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
235 | } |
85f55abea563
adds distance functions for integers as utils
Mike Becker <universe@uap-core.de>
parents:
285
diff
changeset
|
236 | |
349
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
237 | intmax_t ucx_dist_longlong(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
238 | intmax_t a = *((const long long*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
239 | intmax_t b = *((const long long*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
240 | return a - b; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
241 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
242 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
243 | intmax_t ucx_dist_int16(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
244 | intmax_t a = *((const int16_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
245 | intmax_t b = *((const int16_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
246 | return a - b; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
247 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
248 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
249 | intmax_t ucx_dist_int32(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
250 | intmax_t a = *((const int32_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
251 | intmax_t b = *((const int32_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
252 | return a - b; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
253 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
254 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
255 | intmax_t ucx_dist_int64(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
256 | intmax_t a = *((const int64_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
257 | intmax_t b = *((const int64_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
258 | return a - b; |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
259 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
260 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
261 | intmax_t ucx_dist_uint(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
262 | uintmax_t a = *((const unsigned int*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
263 | uintmax_t b = *((const unsigned int*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
264 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
265 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
266 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
267 | intmax_t ucx_dist_ulongint(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
268 | uintmax_t a = *((const unsigned long int*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
269 | uintmax_t b = *((const unsigned long int*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
270 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
271 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
272 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
273 | intmax_t ucx_dist_ulonglong(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
274 | uintmax_t a = *((const unsigned long long*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
275 | uintmax_t b = *((const unsigned long long*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
276 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
277 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
278 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
279 | intmax_t ucx_dist_uint16(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
280 | uintmax_t a = *((const uint16_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
281 | uintmax_t b = *((const uint16_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
282 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
283 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
284 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
285 | intmax_t ucx_dist_uint32(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
286 | uintmax_t a = *((const uint32_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
287 | uintmax_t b = *((const uint32_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
288 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
289 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
290 | |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
291 | intmax_t ucx_dist_uint64(const void *i1, const void *i2, void *data) { |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
292 | uintmax_t a = *((const uint64_t*) i1); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
293 | uintmax_t b = *((const uint64_t*) i2); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
294 | return a > b ? (intmax_t)(a - b) : -(intmax_t)(b - a); |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
295 | } |
05957b1d10a5
adds a broader set of compare and distance functions
Mike Becker <universe@uap-core.de>
parents:
314
diff
changeset
|
296 | |
313
b7753273f0fd
renames ucx_doublecmp() and ucx_floatcmp() to ucx_cmp_double() and ucx_cmp_float()
Mike Becker <universe@uap-core.de>
parents:
312
diff
changeset
|
297 | int ucx_cmp_float(const void *f1, const void *f2, void *epsilon) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
298 | float a = *((const float*) f1); |
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
299 | float b = *((const float*) f2); |
92
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
300 | float e = !epsilon ? 1e-6f : *((float*)epsilon); |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
301 | if (fabsf(a - b) < e) { |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
302 | return 0; |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
303 | } else { |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
304 | return a < b ? -1 : 1; |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
305 | } |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
306 | } |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
307 | |
313
b7753273f0fd
renames ucx_doublecmp() and ucx_floatcmp() to ucx_cmp_double() and ucx_cmp_float()
Mike Becker <universe@uap-core.de>
parents:
312
diff
changeset
|
308 | int ucx_cmp_double(const void *d1, const void *d2, void *epsilon) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
309 | double a = *((const double*) d1); |
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
310 | double b = *((const double*) d2); |
92
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
311 | double e = !epsilon ? 1e-14 : *((double*)epsilon); |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
312 | if (fabs(a - b) < e) { |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
313 | return 0; |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
314 | } else { |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
315 | return a < b ? -1 : 1; |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
316 | } |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
317 | } |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
318 | |
312
e1e3b768ae8b
renames ucx_ptrcmp() to ucx_cmp_ptr()
Mike Becker <universe@uap-core.de>
parents:
311
diff
changeset
|
319 | int ucx_cmp_ptr(const void *ptr1, const void *ptr2, void *data) { |
244
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
320 | const intptr_t p1 = (const intptr_t) ptr1; |
98dc2d3a9b1d
adds const qualifiers to compare, distance and copy function signatures
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
321 | const intptr_t p2 = (const intptr_t) ptr2; |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
322 | if (p1 == p2) { |
89 | 323 | return 0; |
324 | } else { | |
194
0c1b7676e74c
finalized AVL tree interface + added implementation skeleton + fixed ucx_ptrcmp()
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
325 | return p1 < p2 ? -1 : 1; |
89 | 326 | } |
327 | } | |
91
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
328 | |
311
e1f3248576bc
renames ucx_memcmp() to ucx_cmp_mem()
Mike Becker <universe@uap-core.de>
parents:
310
diff
changeset
|
329 | int ucx_cmp_mem(const void *ptr1, const void *ptr2, void *n) { |
91
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
330 | return memcmp(ptr1, ptr2, *((size_t*)n)); |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
331 | } |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
332 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
333 | /* PRINTF FUNCTIONS */ |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
334 | |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
335 | #ifdef va_copy |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
336 | #define UCX_PRINTF_BUFSIZE 256 |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
337 | #else |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
338 | #pragma message("WARNING: C99 va_copy macro not supported by this platform" \ |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
339 | " - limiting ucx_*printf to 2 KiB") |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
340 | #define UCX_PRINTF_BUFSIZE 0x800 |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
341 | #endif |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
342 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
343 | int ucx_fprintf(void *stream, write_func wfc, const char *fmt, ...) { |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
344 | int ret; |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
345 | va_list ap; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
346 | va_start(ap, fmt); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
347 | ret = ucx_vfprintf(stream, wfc, fmt, ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
348 | va_end(ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
349 | return ret; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
350 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
351 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
352 | int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
353 | char buf[UCX_PRINTF_BUFSIZE]; |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
354 | #ifdef va_copy |
144
b6dcc9d112eb
fixed printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
355 | va_list ap2; |
b6dcc9d112eb
fixed printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
356 | va_copy(ap2, ap); |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
357 | int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
358 | if (ret < 0) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
359 | return ret; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
360 | } else if (ret < UCX_PRINTF_BUFSIZE) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
361 | return (int)wfc(buf, 1, ret, stream); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
362 | } else { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
363 | if (ret == INT_MAX) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
364 | errno = ENOMEM; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
365 | return -1; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
366 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
367 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
368 | int len = ret + 1; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
369 | char *newbuf = (char*)malloc(len); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
370 | if (!newbuf) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
371 | return -1; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
372 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
373 | |
144
b6dcc9d112eb
fixed printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
374 | ret = vsnprintf(newbuf, len, fmt, ap2); |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
375 | if (ret > 0) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
376 | ret = (int)wfc(newbuf, 1, ret, stream); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
377 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
378 | free(newbuf); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
379 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
380 | return ret; |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
381 | #else |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
382 | int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap); |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
383 | if (ret < 0) { |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
384 | return ret; |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
385 | } else if (ret < UCX_PRINTF_BUFSIZE) { |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
386 | return (int)wfc(buf, 1, ret, stream); |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
387 | } else { |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
388 | errno = ENOMEM; |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
389 | return -1; |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
390 | } |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
391 | #endif |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
392 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
393 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
394 | sstr_t ucx_asprintf(UcxAllocator *allocator, const char *fmt, ...) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
395 | va_list ap; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
396 | sstr_t ret; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
397 | va_start(ap, fmt); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
398 | ret = ucx_vasprintf(allocator, fmt, ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
399 | va_end(ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
400 | return ret; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
401 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
402 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
403 | sstr_t ucx_vasprintf(UcxAllocator *a, const char *fmt, va_list ap) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
404 | sstr_t s; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
405 | s.ptr = NULL; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
406 | s.length = 0; |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
407 | char buf[UCX_PRINTF_BUFSIZE]; |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
408 | #ifdef va_copy |
144
b6dcc9d112eb
fixed printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
409 | va_list ap2; |
b6dcc9d112eb
fixed printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
142
diff
changeset
|
410 | va_copy(ap2, ap); |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
411 | int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
412 | if (ret > 0 && ret < UCX_PRINTF_BUFSIZE) { |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
413 | s.ptr = (char*)almalloc(a, ret + 1); |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
414 | if (s.ptr) { |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
415 | s.length = (size_t)ret; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
416 | memcpy(s.ptr, buf, ret); |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
417 | s.ptr[s.length] = '\0'; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
418 | } |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
419 | } else if (ret == INT_MAX) { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
420 | errno = ENOMEM; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
421 | } else { |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
422 | int len = ret + 1; |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
423 | s.ptr = (char*)almalloc(a, len); |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
424 | if (s.ptr) { |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
425 | ret = vsnprintf(s.ptr, len, fmt, ap2); |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
426 | if (ret < 0) { |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
427 | free(s.ptr); |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
428 | s.ptr = NULL; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
429 | } else { |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
430 | s.length = (size_t)ret; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
431 | } |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
432 | } |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
433 | } |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
434 | #else |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
435 | int ret = vsnprintf(buf, UCX_PRINTF_BUFSIZE, fmt, ap); |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
436 | if (ret > 0 && ret < UCX_PRINTF_BUFSIZE) { |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
150
diff
changeset
|
437 | s.ptr = (char*)almalloc(a, ret + 1); |
174
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
438 | if (s.ptr) { |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
439 | s.length = (size_t)ret; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
440 | memcpy(s.ptr, buf, ret); |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
441 | s.ptr[s.length] = '\0'; |
bbfe511cfddb
fixed missing malloc return value validation in ucx_vasprintf
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
442 | } |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
443 | } else { |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
444 | errno = ENOMEM; |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
445 | } |
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
446 | #endif |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
447 | return s; |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
448 | } |