Mon, 06 Mar 2017 15:37:40 +0100
ucx_mempool_free() aborts execution instead of just exiting on failure
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 | * |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
224
diff
changeset
|
4 | * Copyright 2016 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 | |
135
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
29 | /** |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
30 | * @file utils.h |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
31 | * |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
32 | * Compare, copy and printf functions. |
135
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
33 | * |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
34 | * @author Mike Becker |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
35 | * @author Olaf Wintermann |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
36 | */ |
a0aa1c15f46b
documented mempool + some fixes
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
37 | |
120 | 38 | #ifndef UCX_UTILS_H |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
39 | #define UCX_UTILS_H |
89 | 40 | |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
41 | #ifdef __cplusplus |
89 | 42 | extern "C" { |
43 | #endif | |
44 | ||
45 | #include "ucx.h" | |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
46 | #include "string.h" |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
47 | #include "allocator.h" |
218
b20d6088795c
fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
48 | #include <inttypes.h> |
89 | 49 | #include <string.h> |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
50 | #include <stdarg.h> |
224
f9ba63fc6a80
documents UCX_STREAM_COPY_BUFSIZE
Mike Becker <universe@uap-core.de>
parents:
223
diff
changeset
|
51 | |
f9ba63fc6a80
documents UCX_STREAM_COPY_BUFSIZE
Mike Becker <universe@uap-core.de>
parents:
223
diff
changeset
|
52 | /** |
f9ba63fc6a80
documents UCX_STREAM_COPY_BUFSIZE
Mike Becker <universe@uap-core.de>
parents:
223
diff
changeset
|
53 | * Default buffer size for ucx_stream_copy() and ucx_stream_ncopy(). |
f9ba63fc6a80
documents UCX_STREAM_COPY_BUFSIZE
Mike Becker <universe@uap-core.de>
parents:
223
diff
changeset
|
54 | */ |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
55 | #define UCX_STREAM_COPY_BUFSIZE 4096 |
89 | 56 | |
57 | /** | |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
58 | * Copies a string. |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
59 | * @param s the string to copy |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
60 | * @param data omitted |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
61 | * @return a pointer to a copy of s1 that can be passed to free(void*) |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
62 | */ |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
63 | void *ucx_strcpy(void *s, void *data); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
64 | |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
65 | /** |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
66 | * Copies a memory area. |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
67 | * @param m a pointer to the memory area |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
68 | * @param n a pointer to the size_t containing the size of the memory area |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
69 | * @return a pointer to a copy of the specified memory area that can |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
70 | * be passed to free(void*) |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
71 | */ |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
72 | void *ucx_memcpy(void *m, void *n); |
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
73 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
74 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
75 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
76 | * Reads data from a stream and writes it to another stream. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
77 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
78 | * @param src the source stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
79 | * @param dest the destination stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
80 | * @param rfnc the read function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
81 | * @param wfnc the write function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
82 | * @param buf a pointer to the copy buffer or <code>NULL</code> if a buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
83 | * shall be implicitly created on the heap |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
84 | * @param bufsize the size of the copy buffer - if <code>NULL</code> was |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
85 | * provided for <code>buf</code>, this is the size of the buffer that shall be |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
86 | * implicitly created |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
87 | * @param n the maximum number of bytes that shall be copied |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
88 | * @return the total number of bytes copied |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
89 | */ |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
90 | size_t ucx_stream_bncopy(void *src, void *dest, read_func rfnc, write_func wfnc, |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
91 | 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:
138
diff
changeset
|
92 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
93 | /** |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
94 | * Shorthand for an unbounded ucx_stream_bncopy call using a default buffer. |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
95 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
96 | * @param src the source stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
97 | * @param dest the destination stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
98 | * @param rfnc the read function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
99 | * @param wfnc the write function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
100 | * @return total number of bytes copied |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
101 | * |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
102 | * @see #UCX_STREAM_COPY_BUFSIZE |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
103 | */ |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
104 | #define ucx_stream_copy(src,dest,rfnc,wfnc) ucx_stream_bncopy(\ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
105 | src, dest, (read_func)rfnc, (write_func)wfnc, \ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
106 | NULL, UCX_STREAM_COPY_BUFSIZE, (size_t)-1) |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
107 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
108 | /** |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
109 | * Shorthand for ucx_stream_bncopy using a default copy buffer. |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
110 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
111 | * @param src the source stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
112 | * @param dest the destination stream |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
113 | * @param rfnc the read function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
114 | * @param wfnc the write function |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
115 | * @param n maximum number of bytes that shall be copied |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
116 | * @return total number of bytes copied |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
117 | */ |
222
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
118 | #define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_bncopy(\ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
119 | src, dest, (read_func)rfnc, (write_func)wfnc, \ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
120 | NULL, UCX_STREAM_COPY_BUFSIZE, n) |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
121 | |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
122 | /** |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
123 | * Shorthand for an unbounded ucx_stream_bncopy call using the specified buffer. |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
124 | * |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
125 | * @param src the source stream |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
126 | * @param dest the destination stream |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
127 | * @param rfnc the read function |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
128 | * @param wfnc the write function |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
129 | * @param buf a pointer to the copy buffer or <code>NULL</code> if a buffer |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
130 | * shall be implicitly created on the heap |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
131 | * @param bufsize the size of the copy buffer - if <code>NULL</code> was |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
132 | * provided for <code>buf</code>, this is the size of the buffer that shall be |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
133 | * implicitly created |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
134 | * @return total number of bytes copied |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
135 | */ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
136 | #define ucx_stream_bcopy(src,dest,rfnc,wfnc, buf, bufsize) ucx_stream_bncopy(\ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
137 | src, dest, (read_func)rfnc, (write_func)wfnc, \ |
e0f850709a5c
changes ucx_stream_Xcopy API
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
138 | buf, bufsize, (size_t)-1) |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
138
diff
changeset
|
139 | |
94
57ea041df22f
renamed comparator to utils module and added copy functions
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
140 | /** |
89 | 141 | * Wraps the strcmp function. |
142 | * @param s1 string one | |
143 | * @param s2 string two | |
144 | * @param data omitted | |
145 | * @return the result of strcmp(s1, s2) | |
146 | */ | |
147 | int ucx_strcmp(void *s1, void *s2, void *data); | |
148 | ||
149 | /** | |
150 | * Wraps the strncmp function. | |
151 | * @param s1 string one | |
152 | * @param s2 string two | |
153 | * @param n a pointer to the size_t containing the third strncmp parameter | |
154 | * @return the result of strncmp(s1, s2, *n) | |
155 | */ | |
156 | int ucx_strncmp(void *s1, void *s2, void *n); | |
157 | ||
158 | /** | |
159 | * Compares two integers of type int. | |
160 | * @param i1 pointer to integer one | |
161 | * @param i2 pointer to integer two | |
162 | * @param data omitted | |
163 | * @return -1, if *i1 is less than *i2, 0 if both are equal, | |
164 | * 1 if *i1 is greater than *i2 | |
165 | */ | |
166 | int ucx_intcmp(void *i1, void *i2, void *data); | |
167 | ||
168 | /** | |
92
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
169 | * Compares two real numbers of type float. |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
170 | * @param f1 pointer to float one |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
171 | * @param f2 pointer to float two |
138
7800811078b8
documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents:
135
diff
changeset
|
172 | * @param data if provided: a pointer to precision (default: 1e-6f) |
92
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
173 | * @return -1, if *f1 is less than *f2, 0 if both are equal, |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
174 | * 1 if *f1 is greater than *f2 |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
175 | */ |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
176 | |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
177 | int ucx_floatcmp(void *f1, void *f2, void *data); |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
178 | |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
179 | /** |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
180 | * Compares two real numbers of type double. |
138
7800811078b8
documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents:
135
diff
changeset
|
181 | * @param d1 pointer to double one |
7800811078b8
documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents:
135
diff
changeset
|
182 | * @param d2 pointer to double two |
7800811078b8
documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents:
135
diff
changeset
|
183 | * @param data if provided: a pointer to precision (default: 1e-14) |
92
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
184 | * @return -1, if *d1 is less than *d2, 0 if both are equal, |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
185 | * 1 if *d1 is greater than *d2 |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
186 | */ |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
187 | int ucx_doublecmp(void *d1, void *d2, void *data); |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
188 | |
7625a8efcc97
added floating point comparators
Mike Becker <universe@uap-core.de>
parents:
91
diff
changeset
|
189 | /** |
89 | 190 | * Compares two pointers. |
191 | * @param ptr1 pointer one | |
192 | * @param ptr2 pointer two | |
193 | * @param data omitted | |
194 | * @return -1 if ptr1 is less than ptr2, 0 if both are equal, | |
195 | * 1 if ptr1 is greater than ptr2 | |
196 | */ | |
197 | int ucx_ptrcmp(void *ptr1, void *ptr2, void *data); | |
198 | ||
91
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
199 | /** |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
200 | * Compares two memory areas. |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
201 | * @param ptr1 pointer one |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
202 | * @param ptr2 pointer two |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
203 | * @param n a pointer to the size_t containing the third parameter for memcmp |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
204 | * @return the result of memcmp(ptr1, ptr2, *n) |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
205 | */ |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
206 | int ucx_memcmp(void *ptr1, void *ptr2, void *n); |
91595a45fad6
added memcmp to the comparator module
Mike Becker <universe@uap-core.de>
parents:
89
diff
changeset
|
207 | |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
208 | /** |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
209 | * A <code>printf()</code> like function which writes the output to a stream by |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
210 | * using a write_func(). |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
211 | * @param stream the stream the data is written to |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
212 | * @param wfc the write function |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
213 | * @param fmt format string |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
214 | * @param ... additional arguments |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
215 | * @return the total number of bytes written |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
216 | */ |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
217 | int ucx_fprintf(void *stream, write_func wfc, const char *fmt, ...); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
218 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
219 | /** |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
220 | * <code>va_list</code> version of ucx_fprintf(). |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
221 | * @param stream the stream the data is written to |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
222 | * @param wfc the write function |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
223 | * @param fmt format string |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
224 | * @param ap argument list |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
225 | * @return the total number of bytes written |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
226 | * @see ucx_fprintf() |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
227 | */ |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
228 | 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
|
229 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
230 | /** |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
231 | * A <code>printf()</code> like function which allocates space for a sstr_t |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
232 | * the result is written to. |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
233 | * |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
234 | * <b>Attention</b>: The sstr_t data is allocated with the allocators |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
235 | * ucx_allocator_malloc() function. So it is implementation dependent, if |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
236 | * the returned sstr_t.ptr pointer must be passed to the allocators |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
237 | * ucx_allocator_free() function manually. |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
238 | * |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
239 | * <b>Note</b>: The sstr_t.ptr of the return value will <i>always</i> be |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
240 | * <code>NULL</code>-terminated. |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
241 | * |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
242 | * @param allocator the UcxAllocator used for allocating the result sstr_t |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
243 | * @param fmt format string |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
244 | * @param ... additional arguments |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
245 | * @return a sstr_t containing the formatted string |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
246 | */ |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
247 | sstr_t ucx_asprintf(UcxAllocator *allocator, const char *fmt, ...); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
248 | |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
249 | /** |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
250 | * <code>va_list</code> version of ucx_asprintf(). |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
251 | * |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
252 | * @param allocator the UcxAllocator used for allocating the result sstr_t |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
253 | * @param fmt format string |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
254 | * @param ap argument list |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
255 | * @return a sstr_t containing the formatted string |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
144
diff
changeset
|
256 | * @see ucx_asprintf() |
142
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
257 | */ |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
258 | sstr_t ucx_vasprintf(UcxAllocator *allocator, const char *fmt, va_list ap); |
ee8cb27d8b8e
added printf functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
259 | |
223
e18884bbad48
fixes ucx_sprintf macro and adds tests for sprintf and bprintf
Mike Becker <universe@uap-core.de>
parents:
222
diff
changeset
|
260 | /** Shortcut for ucx_asprintf() with default allocator. */ |
e18884bbad48
fixes ucx_sprintf macro and adds tests for sprintf and bprintf
Mike Becker <universe@uap-core.de>
parents:
222
diff
changeset
|
261 | #define ucx_sprintf(...) \ |
e18884bbad48
fixes ucx_sprintf macro and adds tests for sprintf and bprintf
Mike Becker <universe@uap-core.de>
parents:
222
diff
changeset
|
262 | ucx_asprintf(ucx_default_allocator(), __VA_ARGS__) |
e18884bbad48
fixes ucx_sprintf macro and adds tests for sprintf and bprintf
Mike Becker <universe@uap-core.de>
parents:
222
diff
changeset
|
263 | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
264 | /** |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
224
diff
changeset
|
265 | * A <code>printf()</code> like function which writes the output to a |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
266 | * UcxBuffer. |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
267 | * |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
268 | * @param buffer the buffer the data is written to |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
269 | * @param ... format string and additional arguments |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
270 | * @return the total number of bytes written |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
271 | * @see ucx_fprintf() |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
272 | */ |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
273 | #define ucx_bprintf(buffer, ...) ucx_fprintf((UcxBuffer*)buffer, \ |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
274 | (write_func)ucx_buffer_write, __VA_ARGS__) |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
275 | |
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
276 | #ifdef __cplusplus |
89 | 277 | } |
278 | #endif | |
279 | ||
150
1cf2eabf94ed
fixes for ultra fail not C99 supporting VC wannebe compiler
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
280 | #endif /* UCX_UTILS_H */ |
89 | 281 |