Tue, 07 Jan 2025 00:12:46 +0100
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
fixes #545
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | /** |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
30 | * @file buffer.h |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
32 | * @brief Advanced buffer implementation. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | * Instances of CxBuffer can be used to read from or to write to like one |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | * would do with a stream. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | * Some features for convenient use of the buffer |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | * can be enabled. See the documentation of the macro constants for more |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | * information. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
41 | * @author Mike Becker |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
42 | * @author Olaf Wintermann |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
43 | * @copyright 2-Clause BSD License |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | #ifndef UCX_BUFFER_H |
484
9e6900b1cf9d
add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents:
483
diff
changeset
|
47 | #define UCX_BUFFER_H |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | |
484
9e6900b1cf9d
add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents:
483
diff
changeset
|
49 | #include "common.h" |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
50 | #include "allocator.h" |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
52 | #ifdef __cplusplus |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | extern "C" { |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | #endif |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | * No buffer features enabled (all flags cleared). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | #define CX_BUFFER_DEFAULT 0x00 |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | * If this flag is enabled, the buffer will automatically free its contents when destroyed. |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
63 | * |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
64 | * Do NOT set this flag together with #CX_BUFFER_COPY_ON_WRITE. It will be automatically |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
65 | * set when the copy-on-write operations is performed. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | #define CX_BUFFER_FREE_CONTENTS 0x01 |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | /** |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
70 | * If this flag is enabled, the buffer will automatically extend its capacity. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | #define CX_BUFFER_AUTO_EXTEND 0x02 |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
74 | /** |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
75 | * If this flag is enabled, the buffer will allocate new memory when written to. |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
76 | * |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
77 | * The current contents of the buffer will be copied to the new memory and the flag |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
78 | * will be cleared while the #CX_BUFFER_FREE_CONTENTS flag will be set automatically. |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
79 | */ |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
80 | #define CX_BUFFER_COPY_ON_WRITE 0x04 |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
81 | |
1028
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
82 | /** |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
83 | * If this flag is enabled, the buffer will copy its contents to a new memory area on reallocation. |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
84 | * |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
85 | * After performing the copy, the flag is automatically cleared. |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
86 | * This flag has no effect on buffers which do not have #CX_BUFFER_AUTO_EXTEND set, which is why |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
87 | * buffers automatically admit the auto-extend flag when initialized with copy-on-extend enabled. |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
88 | */ |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
89 | #define CX_BUFFER_COPY_ON_EXTEND 0x08 |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
90 | |
1110 | 91 | /** |
1112
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
92 | * Function pointer for cxBufferWrite that is compatible with cx_write_func. |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
93 | * @see cx_write_func |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
94 | */ |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
95 | #define cxBufferWriteFunc ((cx_write_func) cxBufferWrite) |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
96 | /** |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
97 | * Function pointer for cxBufferRead that is compatible with cx_read_func. |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
98 | * @see cx_read_func |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
99 | */ |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
100 | #define cxBufferReadFunc ((cx_read_func) cxBufferRead) |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
101 | |
22dc2163fffd
add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
1110
diff
changeset
|
102 | /** |
1110 | 103 | * Configuration for automatic flushing. |
104 | */ | |
105 | struct cx_buffer_flush_config_s { | |
106 | /** | |
107 | * The buffer may not extend beyond this threshold before starting to flush. | |
108 | * | |
109 | * Only used when the buffer uses #CX_BUFFER_AUTO_EXTEND. | |
110 | * The threshold will be the maximum capacity the buffer is extended to | |
111 | * before flushing. | |
112 | */ | |
113 | size_t threshold; | |
114 | /** | |
115 | * The block size for the elements to flush. | |
116 | */ | |
117 | size_t blksize; | |
118 | /** | |
119 | * The maximum number of blocks to flush in one cycle. | |
120 | * | |
121 | * @attention while it is guaranteed that cxBufferFlush() will not flush | |
122 | * more blocks, this is not necessarily the case for cxBufferWrite(). | |
123 | * After performing a flush cycle, cxBufferWrite() will retry the write | |
124 | * operation and potentially trigger another flush cycle, until the | |
125 | * flush target accepts no more data. | |
126 | */ | |
127 | size_t blkmax; | |
128 | ||
129 | /** | |
130 | * The target for write function. | |
131 | */ | |
132 | void *target; | |
133 | ||
134 | /** | |
135 | * The write-function used for flushing. | |
136 | * If NULL, the flushed content gets discarded. | |
137 | */ | |
138 | cx_write_func wfunc; | |
139 | }; | |
140 | ||
141 | /** | |
142 | * Type alais for the flush configuration struct. | |
143 | * | |
144 | * @code | |
145 | * struct cx_buffer_flush_config_s { | |
146 | * size_t threshold; | |
147 | * size_t blksize; | |
148 | * size_t blkmax; | |
149 | * void *target; | |
150 | * cx_write_func wfunc; | |
151 | * }; | |
152 | * @endcode | |
153 | */ | |
154 | typedef struct cx_buffer_flush_config_s CxBufferFlushConfig; | |
155 | ||
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | /** Structure for the UCX buffer data. */ |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
157 | struct cx_buffer_s { |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | /** A pointer to the buffer contents. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | union { |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | * Data is interpreted as text. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | char *space; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | * Data is interpreted as binary. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | unsigned char *bytes; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | }; |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
169 | /** The allocator to use for automatic memory management. */ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
170 | const CxAllocator *allocator; |
1110 | 171 | /** |
172 | * Optional flush configuration | |
173 | * | |
174 | * @see cxBufferEnableFlushing() | |
175 | */ | |
176 | CxBufferFlushConfig* flush; | |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | /** Current position of the buffer. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | size_t pos; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | /** Current capacity (i.e. maximum size) of the buffer. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | size_t capacity; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | /** Current size of the buffer content. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | size_t size; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | * Flag register for buffer features. |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
185 | * @see #CX_BUFFER_DEFAULT |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
186 | * @see #CX_BUFFER_FREE_CONTENTS |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
187 | * @see #CX_BUFFER_AUTO_EXTEND |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
188 | * @see #CX_BUFFER_COPY_ON_WRITE |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
189 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | int flags; |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
191 | }; |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | * UCX buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | */ |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
196 | typedef struct cx_buffer_s CxBuffer; |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | /** |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
199 | * Initializes a fresh buffer. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
201 | * You may also provide a read-only @p space, in which case |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
202 | * you will need to cast the pointer, and you should set the |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
203 | * #CX_BUFFER_COPY_ON_WRITE flag. |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
204 | * |
1029
c065d196a2c8
add advice to set the size of a buffer initialized with existing data
Mike Becker <universe@uap-core.de>
parents:
1028
diff
changeset
|
205 | * You need to set the size manually after initialization, if |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
206 | * you provide @p space which already contains data. |
1029
c065d196a2c8
add advice to set the size of a buffer initialized with existing data
Mike Becker <universe@uap-core.de>
parents:
1028
diff
changeset
|
207 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
208 | * When you specify stack memory as @p space and decide to use |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
209 | * the auto-extension feature, you @em must use the |
1028
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
210 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
211 | * #CX_BUFFER_AUTO_EXTEND flag. |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
212 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
213 | * @note You may provide @c NULL as argument for @p space. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | * Then this function will allocate the space and enforce |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
215 | * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
216 | * copy-on-write should be avoided, because the allocated |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
217 | * space will be leaking after the copy-on-write operation. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
219 | * @param buffer the buffer to initialize |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
220 | * @param space pointer to the memory area, or @c NULL to allocate |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | * new memory |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
222 | * @param capacity the capacity of the buffer |
673
60fb6aec157d
make allocator in cxBufferInit optional
Mike Becker <universe@uap-core.de>
parents:
628
diff
changeset
|
223 | * @param allocator the allocator this buffer shall use for automatic |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
224 | * memory management |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
225 | * (if @c NULL, a default stdlib allocator will be used) |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
226 | * @param flags buffer features (see cx_buffer_s.flags) |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
227 | * @return zero on success, non-zero if a required allocation failed |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
229 | cx_attr_nonnull_arg(1) |
501
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
230 | int cxBufferInit( |
9a08f5e515cc
add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents:
500
diff
changeset
|
231 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | void *space, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | size_t capacity, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
234 | const CxAllocator *allocator, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | int flags |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | /** |
1110 | 239 | * Configures the buffer for flushing. |
240 | * | |
241 | * Flushing can happen automatically when data is written | |
242 | * to the buffer (see cxBufferWrite()) or manually when | |
243 | * cxBufferFlush() is called. | |
244 | * | |
245 | * @param buffer the buffer | |
246 | * @param config the flush configuration | |
247 | * @retval zero success | |
248 | * @retval non-zero failure | |
249 | * @see cxBufferFlush() | |
250 | * @see cxBufferWrite() | |
251 | */ | |
252 | cx_attr_nonnull | |
253 | int cxBufferEnableFlushing( | |
254 | CxBuffer *buffer, | |
255 | CxBufferFlushConfig config | |
256 | ); | |
257 | ||
258 | /** | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
259 | * Destroys the buffer contents. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
260 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
261 | * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
262 | * If you want to free the memory of the entire buffer, use cxBufferFree(). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
263 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
264 | * @param buffer the buffer which contents shall be destroyed |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
265 | * @see cxBufferInit() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
266 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
267 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
268 | void cxBufferDestroy(CxBuffer *buffer); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
269 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
270 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
271 | * Deallocates the buffer. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
272 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
273 | * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
274 | * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
275 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
276 | * @remark As with all free() functions, this accepts @c NULL arguments in which |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
277 | * case it does nothing. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
278 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
279 | * @param buffer the buffer to deallocate |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
280 | * @see cxBufferCreate() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
281 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
282 | void cxBufferFree(CxBuffer *buffer); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
283 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
284 | /** |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
285 | * Allocates and initializes a fresh buffer. |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
286 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
287 | * You may also provide a read-only @p space, in which case |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
288 | * you will need to cast the pointer, and you should set the |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
289 | * #CX_BUFFER_COPY_ON_WRITE flag. |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
290 | * When you specify stack memory as @p space and decide to use |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
291 | * the auto-extension feature, you @em must use the |
1028
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
292 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the |
3e4905241838
add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents:
1024
diff
changeset
|
293 | * #CX_BUFFER_AUTO_EXTEND flag. |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
294 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
295 | * @note You may provide @c NULL as argument for @p space. |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
296 | * Then this function will allocate the space and enforce |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
297 | * the #CX_BUFFER_FREE_CONTENTS flag. |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
298 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
299 | * @param space pointer to the memory area, or @c NULL to allocate |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
300 | * new memory |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
301 | * @param capacity the capacity of the buffer |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
302 | * @param allocator the allocator to use for allocating the structure and the automatic |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
303 | * memory management within the buffer |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
304 | * (if @c NULL, a default stdlib allocator will be used) |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
305 | * @param flags buffer features (see cx_buffer_s.flags) |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
306 | * @return a pointer to the buffer on success, @c NULL if a required allocation failed |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
307 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
308 | cx_attr_malloc |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
309 | cx_attr_dealloc(cxBufferFree, 1) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
310 | cx_attr_nodiscard |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
311 | CxBuffer *cxBufferCreate( |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
312 | void *space, |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
313 | size_t capacity, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
314 | const CxAllocator *allocator, |
683
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
315 | int flags |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
316 | ); |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
317 | |
aa0d09f2d81c
add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
318 | /** |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
319 | * Shifts the contents of the buffer by the given offset. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
321 | * If the offset is positive, the contents are shifted to the right. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | * If auto extension is enabled, the buffer grows, if necessary. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
323 | * In case the auto extension fails, this function returns a non-zero value and |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | * no contents are changed. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | * If auto extension is disabled, the contents that do not fit into the buffer |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | * are discarded. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | * If the offset is negative, the contents are shifted to the left where the |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
329 | * first @p shift bytes are discarded. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | * The new size of the buffer is the old size minus the absolute shift value. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | * If this value is larger than the buffer size, the buffer is emptied (but |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | * not cleared, see the security note below). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | * The buffer position gets shifted alongside with the content but is kept |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | * within the boundaries of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
337 | * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
338 | * cxBufferShiftRight() functions using a @c size_t as parameter type. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
340 | * @attention |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
341 | * Security Note: The shifting operation does @em not erase the previously occupied memory cells. |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
342 | * But you can easily do that manually, e.g. by calling |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
531
1b8624c8448e
fix erroneous doc for cxBufferShift
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
344 | * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | * for a left shift. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
347 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
348 | * @param shift the shift offset (negative means left shift) |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
349 | * @retval zero success |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
350 | * @retval non-zero if a required auto-extension or copy-on-write fails |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
351 | * @see cxBufferShiftLeft() |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
352 | * @see cxBufferShiftRight() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
353 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
354 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | int cxBufferShift( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
356 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | off_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | * Shifts the buffer to the right. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | * See cxBufferShift() for details. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
363 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
364 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
365 | * @param shift the shift offset |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
366 | * @retval zero success |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
367 | * @retval non-zero if a required auto-extension or copy-on-write fails |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
368 | * @see cxBufferShift() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
370 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | int cxBufferShiftRight( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
372 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
373 | size_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
374 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
375 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
376 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
377 | * Shifts the buffer to the left. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
378 | * See cxBufferShift() for details. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
379 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
380 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
381 | * @param shift the positive shift offset |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
382 | * @retval zero success |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
383 | * @retval non-zero if the buffer uses copy-on-write and the allocation fails |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
384 | * @see cxBufferShift() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
385 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
386 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
387 | int cxBufferShiftLeft( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
388 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
389 | size_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
390 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
391 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
392 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
393 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
394 | * Moves the position of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
395 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
396 | * The new position is relative to the @p whence argument. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
397 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
398 | * @li @c SEEK_SET marks the start of the buffer. |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
399 | * @li @c SEEK_CUR marks the current position. |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
400 | * @li @c SEEK_END marks the end of the buffer. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
401 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
402 | * With an offset of zero, this function sets the buffer position to zero |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
403 | * (@c SEEK_SET), the buffer size (@c SEEK_END) or leaves the buffer position |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
404 | * unchanged (@c SEEK_CUR). |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
405 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
406 | * @param buffer the buffer |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
407 | * @param offset position offset relative to @p whence |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
408 | * @param whence one of @c SEEK_SET, @c SEEK_CUR or @c SEEK_END |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
409 | * @retval zero success |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
410 | * @retval non-zero if the position is invalid |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
411 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
412 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
413 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
414 | int cxBufferSeek( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
415 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
416 | off_t offset, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
417 | int whence |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
418 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
419 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
420 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
421 | * Clears the buffer by resetting the position and deleting the data. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
422 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
423 | * The data is deleted by zeroing it with a call to memset(). |
761
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
424 | * If you do not need that, you can use the faster cxBufferReset(). |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
425 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
426 | * @note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function |
1024
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
427 | * will not erase the data and behave exactly as cxBufferReset(). |
8f99f6c28bd3
add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents:
1016
diff
changeset
|
428 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
429 | * @param buffer the buffer to be cleared |
761
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
430 | * @see cxBufferReset() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
431 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
432 | cx_attr_nonnull |
529
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
433 | void cxBufferClear(CxBuffer *buffer); |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
434 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
435 | /** |
761
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
436 | * Resets the buffer by resetting the position and size to zero. |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
437 | * |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
438 | * The data in the buffer is not deleted. If you need a safe |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
439 | * reset of the buffer, use cxBufferClear(). |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
440 | * |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
441 | * @param buffer the buffer to be cleared |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
442 | * @see cxBufferClear() |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
443 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
444 | cx_attr_nonnull |
761
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
445 | void cxBufferReset(CxBuffer *buffer); |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
446 | |
61d5197d612b
add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
447 | /** |
757
49ceea78fce7
fix incorrect documentation of cxBufferEof()
Mike Becker <universe@uap-core.de>
parents:
683
diff
changeset
|
448 | * Tests, if the buffer position has exceeded the buffer size. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
449 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
450 | * @param buffer the buffer to test |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
451 | * @retval true if the current buffer position has exceeded the last |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
452 | * byte of the buffer's contents |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
453 | * @retval false otherwise |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
454 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
455 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
456 | cx_attr_nodiscard |
1004
d8044fd5005c
make cxBufferEof() return a bool
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
457 | bool cxBufferEof(const CxBuffer *buffer); |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
458 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
459 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
460 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
461 | * Ensures that the buffer has a minimum capacity. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
462 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
463 | * If the current capacity is not sufficient, the buffer will be extended. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
464 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
465 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
466 | * @param capacity the minimum required capacity for this buffer |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
467 | * @retval zero the capacity was already sufficient or successfully increased |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
468 | * @retval non-zero on allocation failure |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
469 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
470 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
471 | int cxBufferMinimumCapacity( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
472 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
473 | size_t capacity |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
474 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
475 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
476 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
477 | * Writes data to a CxBuffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
478 | * |
1110 | 479 | * If automatic flushing is not enabled, the data is simply written into the |
480 | * buffer at the current position and the position of the buffer is increased | |
481 | * by the number of bytes written. | |
482 | * | |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
483 | * If flushing is enabled and the buffer needs to flush, the data is flushed to |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
484 | * the target until the target signals that it cannot take more data by |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
485 | * returning zero via the respective write function. In that case, the remaining |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
486 | * data in this buffer is shifted to the beginning of this buffer so that the |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
487 | * newly available space can be used to append as much data as possible. This |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
488 | * function only stops writing more elements, when the flush target and this |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
489 | * buffer are both incapable of taking more data or all data has been written. |
1110 | 490 | * If number of items that shall be written is larger than the buffer can hold, |
491 | * the first items from @c ptr are directly relayed to the flush target, if | |
492 | * possible. | |
493 | * The number returned by this function is only the number of elements from | |
494 | * @c ptr that could be written to either the flush target or the buffer. | |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
495 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
496 | * @note The signature is compatible with the fwrite() family of functions. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
497 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
498 | * @param ptr a pointer to the memory area containing the bytes to be written |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
499 | * @param size the length of one element |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
500 | * @param nitems the element count |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
501 | * @param buffer the CxBuffer to write to |
537
16219eba3a0a
fix doc error for cxBufferWrite
Mike Becker <universe@uap-core.de>
parents:
531
diff
changeset
|
502 | * @return the total count of elements written |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
503 | * @see cxBufferAppend() |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
504 | * @see cxBufferRead() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
505 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
506 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
507 | size_t cxBufferWrite( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
508 | const void *ptr, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
509 | size_t size, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
510 | size_t nitems, |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
511 | CxBuffer *buffer |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
512 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
513 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
514 | /** |
1030
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
515 | * Appends data to a CxBuffer. |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
516 | * |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
517 | * The data is always appended to current data within the buffer, |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
518 | * regardless of the current position. |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
519 | * This is especially useful when the buffer is primarily meant for reading |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
520 | * while additional data is added to the buffer occasionally. |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
521 | * Consequently, the position of the buffer is unchanged after this operation. |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
522 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
523 | * @note The signature is compatible with the fwrite() family of functions. |
1030
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
524 | * |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
525 | * @param ptr a pointer to the memory area containing the bytes to be written |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
526 | * @param size the length of one element |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
527 | * @param nitems the element count |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
528 | * @param buffer the CxBuffer to write to |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
529 | * @return the total count of elements written |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
530 | * @see cxBufferWrite() |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
531 | * @see cxBufferRead() |
1030
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
532 | */ |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
533 | cx_attr_nonnull |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
534 | size_t cxBufferAppend( |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
535 | const void *ptr, |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
536 | size_t size, |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
537 | size_t nitems, |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
538 | CxBuffer *buffer |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
539 | ); |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
540 | |
06091e067bee
add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents:
1029
diff
changeset
|
541 | /** |
1110 | 542 | * Performs a single flush-run on the specified buffer. |
543 | * | |
544 | * Does nothing when the position in the buffer is zero. | |
545 | * Otherwise, the data until the current position minus | |
546 | * one is considered for flushing. | |
547 | * Note carefully that flushing will never exceed the | |
548 | * current @em position, even when the size of the | |
549 | * buffer is larger than the current position. | |
550 | * | |
551 | * One flush run will try to flush @c blkmax many | |
552 | * blocks of size @c blksize until either the @p buffer | |
553 | * has no more data to flush or the write function | |
554 | * used for flushing returns zero. | |
555 | * | |
556 | * The buffer is shifted left for that many bytes | |
557 | * the flush operation has successfully flushed. | |
558 | * | |
559 | * @par Example 1 | |
560 | * Assume you have a buffer with size 340 and you are | |
561 | * at position 200. The flush configuration is | |
562 | * @c blkmax=4 and @c blksize=64 . | |
563 | * Assume that the entire flush operation is successful. | |
564 | * All 200 bytes on the left hand-side from the current | |
565 | * position are written. | |
566 | * That means, the size of the buffer is now 140 and the | |
567 | * position is zero. | |
568 | * | |
569 | * @par Example 2 | |
570 | * Same as Example 1, but now the @c blkmax is 1. | |
571 | * The size of the buffer is now 276 and the position is 136. | |
572 | * | |
573 | * @par Example 3 | |
574 | * Same as Example 1, but now assume the flush target | |
575 | * only accepts 100 bytes before returning zero. | |
576 | * That means, the flush operations manages to flush | |
577 | * one complete block and one partial block, ending | |
578 | * up with a buffer with size 240 and position 100. | |
579 | * | |
580 | * @remark Just returns zero when flushing was not enabled with | |
581 | * cxBufferEnableFlushing(). | |
582 | * | |
583 | * @remark When the buffer uses copy-on-write, the memory | |
584 | * is copied first, before attempting any flush. | |
585 | * This is, however, considered an erroneous use of the | |
586 | * buffer, because it does not make much sense to put | |
587 | * readonly data into an UCX buffer for flushing, instead | |
588 | * of writing it directly to the target. | |
589 | * | |
590 | * @param buffer the buffer | |
591 | * @return the number of successfully flushed bytes | |
592 | * @see cxBufferEnableFlushing() | |
593 | */ | |
594 | cx_attr_nonnull | |
595 | size_t cxBufferFlush(CxBuffer *buffer); | |
596 | ||
597 | /** | |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
598 | * Reads data from a CxBuffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
599 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
600 | * The position of the buffer is increased by the number of bytes read. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
601 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
602 | * @note The signature is compatible with the fread() family of functions. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
603 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
604 | * @param ptr a pointer to the memory area where to store the read data |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
605 | * @param size the length of one element |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
606 | * @param nitems the element count |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
607 | * @param buffer the CxBuffer to read from |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
608 | * @return the total number of elements read |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
609 | * @see cxBufferWrite() |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
610 | * @see cxBufferAppend() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
611 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
612 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
613 | size_t cxBufferRead( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
614 | void *ptr, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
615 | size_t size, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
616 | size_t nitems, |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
617 | CxBuffer *buffer |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
618 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
619 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
620 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
621 | * Writes a character to a buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
622 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
623 | * The least significant byte of the argument is written to the buffer. If the |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
624 | * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, |
1005
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
625 | * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
626 | * is disabled or buffer extension fails, @c EOF is returned. |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
627 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
628 | * On successful write, the position of the buffer is increased. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
629 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
630 | * If you just want to write a null-terminator at the current position, you |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
631 | * should use cxBufferTerminate() instead. |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
632 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
633 | * @param buffer the buffer to write to |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
634 | * @param c the character to write |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
635 | * @return the byte that has been written or @c EOF when the end of the stream is |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
636 | * reached and automatic extension is not enabled or not possible |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
637 | * @see cxBufferTerminate() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
638 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
639 | cx_attr_nonnull |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
640 | int cxBufferPut( |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
641 | CxBuffer *buffer, |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
642 | int c |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
643 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
644 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
645 | /** |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
646 | * Writes a terminating zero to a buffer at the current position. |
1005
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
647 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
648 | * On successful write, @em neither the position @em nor the size of the buffer is |
1005
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
649 | * increased. |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
650 | * |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
651 | * The purpose of this function is to have the written data ready to be used as |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
652 | * a C string. |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
653 | * |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
654 | * @param buffer the buffer to write to |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
655 | * @return zero, if the terminator could be written, non-zero otherwise |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
656 | */ |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
657 | cx_attr_nonnull |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
658 | int cxBufferTerminate(CxBuffer *buffer); |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
659 | |
67fa386ce600
add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents:
1004
diff
changeset
|
660 | /** |
529
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
661 | * Writes a string to a buffer. |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
662 | * |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
663 | * This is a convenience function for <code>cxBufferWrite(str, 1, strlen(str), buffer)</code>. |
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
664 | * |
529
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
665 | * @param buffer the buffer |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
666 | * @param str the zero-terminated string |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
667 | * @return the number of bytes written |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
668 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
669 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
670 | cx_attr_cstr_arg(2) |
529
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
671 | size_t cxBufferPutString( |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
672 | CxBuffer *buffer, |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
673 | const char *str |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
674 | ); |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
675 | |
814d51173f20
#171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents:
501
diff
changeset
|
676 | /** |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
677 | * Gets a character from a buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
678 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
679 | * The current position of the buffer is increased after a successful read. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
680 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
681 | * @param buffer the buffer to read from |
1090
4384fe041d6e
refine docs for buffer.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
1030
diff
changeset
|
682 | * @return the character or @c EOF, if the end of the buffer is reached |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
683 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
948
diff
changeset
|
684 | cx_attr_nonnull |
500
eb9e7bd40a8e
do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents:
489
diff
changeset
|
685 | int cxBufferGet(CxBuffer *buffer); |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
686 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
687 | #ifdef __cplusplus |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
688 | } |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
689 | #endif |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
690 | |
628
1e2be40f0cb5
use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents:
567
diff
changeset
|
691 | #endif // UCX_BUFFER_H |