Tue, 28 Dec 2021 14:25:05 +0100
use c99 bool + add test for low level find
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 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | * \file buffer.h |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * \brief Advanced buffer implementation. |
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 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | * \author Mike Becker |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | * \author Olaf Wintermann |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | * \version 3.0 |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | * \copyright 2-Clause BSD License |
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 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | #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
|
48 | #define UCX_BUFFER_H |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | |
484
9e6900b1cf9d
add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents:
483
diff
changeset
|
50 | #include "common.h" |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | #include <stdio.h> |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | #ifdef __cplusplus |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | extern "C" { |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | #endif |
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 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | * No buffer features enabled (all flags cleared). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | #define CX_BUFFER_DEFAULT 0x00 |
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 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | * If this flag is enabled, the buffer will automatically free its contents when destroyed. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | #define CX_BUFFER_FREE_CONTENTS 0x01 |
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 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | * If this flag is enabled, the buffer will automatically extends its capacity. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | #define CX_BUFFER_AUTO_EXTEND 0x02 |
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 | /** Structure for the UCX buffer data. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | typedef struct { |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | /** A pointer to the buffer contents. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | union { |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | * Data is interpreted as text. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | char *space; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | * Data is interpreted as binary. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | unsigned char *bytes; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | }; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | /** Current position of the buffer. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | size_t pos; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | /** Current capacity (i.e. maximum size) of the buffer. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | size_t capacity; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | /** Current size of the buffer content. */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | size_t size; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | * Flag register for buffer features. |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
93 | * @see #CX_BUFFER_DEFAULT |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
94 | * @see #CX_BUFFER_FREE_CONTENTS |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
95 | * @see #CX_BUFFER_AUTO_EXTEND |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | int flags; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | } cx_buffer_s; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | * UCX buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | typedef cx_buffer_s *CxBuffer; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | * Creates a new buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | * \note You may provide \c NULL as argument for \p space. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | * Then this function will allocate the space and enforce |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | * the #CX_BUFFER_FREE_CONTENTS flag. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
112 | * @param space pointer to the memory area, or <code>NULL</code> to allocate |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | * new memory |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
114 | * @param capacity the capacity of the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
115 | * @param flags buffer features (see cx_buffer_s.flags) |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
116 | * @return the new buffer |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | CxBuffer cxBufferCreate( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | void *space, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | size_t capacity, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | int flags |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | * Destroys a buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, the contents of the buffer |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | * are also freed. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
130 | * @param buffer the buffer to destroy |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | void cxBufferDestroy(CxBuffer buffer); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | * Creates a new buffer and fills it with content copied from another buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | * \note The #CX_BUFFER_FREE_CONTENTS feature is enforced for the new buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
139 | * @param src the source buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
140 | * @param start the start position of extraction |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
141 | * @param length the count of bytes to extract (must not be zero) |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
142 | * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled) |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
143 | * @return a new buffer containing the extraction |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | CxBuffer cxBufferExtract( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | CxBuffer src, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | size_t start, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | size_t length, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | int flags |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | * A shorthand macro for copying an entire buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
155 | * @param src the source buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
156 | * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled) |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
157 | * @return a new buffer with the copied content |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | #define cxBufferClone(src, flags) cxBufferExtract(src, 0, (src)->capacity, flags) |
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 | |
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 | * 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
|
164 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | * 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
|
166 | * 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
|
167 | * 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
|
168 | * no contents are changed. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | * 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
|
170 | * are discarded. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | * If the offset is negative, the contents are shifted to the left where the |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | * first \p shift bytes are discarded. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | * 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
|
175 | * 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
|
176 | * not cleared, see the security note below). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | * 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
|
179 | * within the boundaries of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | * \note For situations where \c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | * cxBufferShiftRight() functions using a \c size_t as parameter type. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
184 | * \attention |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
185 | * Security Note: The shifting operation does \em not erase the previously occupied memory cells. |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
186 | * 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
|
187 | * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 | * <code>memset(buffer->size, 0, buffer->capacity - buffer->size)</code> |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
189 | * for a left shift. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
191 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
192 | * @param shift the shift offset (negative means left shift) |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
193 | * @return 0 on success, non-zero if a required auto-extension fails |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | int cxBufferShift( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | off_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | * Shifts the buffer to the right. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | * See cxBufferShift() for details. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
204 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
205 | * @param shift the shift offset |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
206 | * @return 0 on success, non-zero if a required auto-extension fails |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
207 | * @see cxBufferShift() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | int cxBufferShiftRight( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | size_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | * Shifts the buffer to the left. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | * See cxBufferShift() for details. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * \note Since a left shift cannot fail due to memory allocation problems, this |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | * function always returns zero. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
221 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
222 | * @param shift the positive shift offset |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
223 | * @return always zero |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
224 | * @see cxBufferShift() |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | int cxBufferShiftLeft( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | size_t shift |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | * Moves the position of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | * The new position is relative to the \p whence argument. |
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 | * \li \c SEEK_SET marks the start of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | * \li \c SEEK_CUR marks the current position. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | * \li \c SEEK_END marks the end of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | * With an offset of zero, this function sets the buffer position to zero |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | * (\c SEEK_SET), the buffer size (\c SEEK_END) or leaves the buffer position |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | * unchanged (\c SEEK_CUR). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
245 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
246 | * @param offset position offset relative to \p whence |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
247 | * @param whence one of \c SEEK_SET, \c SEEK_CUR or \c SEEK_END |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
248 | * @return 0 on success, non-zero if the position is invalid |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
250 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
251 | int cxBufferSeek( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | off_t offset, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | int whence |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | * 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
|
259 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | * The data is deleted by zeroing it with a call to memset(). |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
262 | * @param buffer the buffer to be cleared |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | #define cxBufferClear(buffer) memset((buffer)->bytes, 0, (buffer)->size); \ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
265 | (buffer)->size = 0; (buffer)->pos = 0; |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
266 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | * Tests, if the buffer position has exceeded the buffer capacity. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
270 | * @param buffer the buffer to test |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
271 | * @return non-zero, if the current buffer position has exceeded the last |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | * available byte of the buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | int cxBufferEof(CxBuffer buffer); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | * Ensures that the buffer has a minimum capacity. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
280 | * 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
|
281 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
282 | * @param buffer the buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
283 | * @param capacity the minimum required capacity for this buffer |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
284 | * @return 0 on success or a non-zero value on failure |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | int cxBufferMinimumCapacity( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
287 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | size_t capacity |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | * Writes data to a CxBuffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | * The position of the buffer is increased by the number of bytes written. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
295 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | * \note The signature is compatible with the fwrite() family of functions. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
298 | * @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
|
299 | * @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
|
300 | * @param nitems the element count |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
301 | * @param buffer the CxBuffer to write to |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
302 | * @return the total count of bytes written |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
303 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
304 | size_t cxBufferWrite( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
305 | const void *ptr, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
306 | size_t size, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
307 | size_t nitems, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
308 | CxBuffer buffer |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
310 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
311 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
312 | * Reads data from a CxBuffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
314 | * 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
|
315 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | * \note The signature is compatible with the fread() family of functions. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
317 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
318 | * @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
|
319 | * @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
|
320 | * @param nitems the element count |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
321 | * @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
|
322 | * @return the total number of elements read |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
323 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | size_t cxBufferRead( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | void *ptr, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | size_t size, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | size_t nitems, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | CxBuffer buffer |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | * Writes a character to a buffer. |
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 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
|
335 | * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature is |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | * disabled or buffer extension fails, \c EOF is returned. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | * 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
|
340 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
341 | * @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
|
342 | * @param c the character to write |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
343 | * @return the byte that has bean 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
|
344 | * reached and automatic extension is not enabled or not possible |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | int cxBufferPut( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | int c |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
352 | * Gets a character from a buffer. |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
353 | * |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
354 | * 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
|
355 | * |
485
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
356 | * @param buffer the buffer to read from |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
357 | * @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
|
358 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | int cxBufferGet(CxBuffer buffer); |
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 | /** |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | * Writes a string to a buffer. |
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 str the zero-terminated string |
6a86ad3d8c03
use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents:
484
diff
changeset
|
366 | * @return the number of bytes written |
483
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
367 | */ |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
368 | size_t cxBufferPutString( |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | CxBuffer buffer, |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
370 | const char *str |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | ); |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
372 | |
929016224c3c
add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
373 | #ifdef __cplusplus |
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 | #endif |
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 | #endif /* UCX_BUFFER_H */ |