Mon, 30 Dec 2019 09:52:07 +0100
closes array branch towards ucx 2.1 release
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
1 | /* |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
3 | * |
259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
27 | */ |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
28 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
29 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
30 | * @file buffer.h |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
31 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
32 | * Advanced buffer implementation. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
33 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
34 | * Instances of UcxBuffer can be used to read from or to write to like one |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
35 | * would do with a stream. This allows the use of ucx_stream_copy() to copy |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
36 | * contents from one buffer to another. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
37 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
38 | * Some features for convenient use of the buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
39 | * can be enabled. See the documentation of the macro constants for more |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
40 | * information. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
41 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
42 | * @author Mike Becker |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
43 | * @author Olaf Wintermann |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
44 | */ |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
45 | |
120 | 46 | #ifndef UCX_BUFFER_H |
47 | #define UCX_BUFFER_H | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | |
259 | 49 | #include "ucx.h" |
62 | 50 | #include <sys/types.h> |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | #include <stdio.h> |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | #ifdef __cplusplus |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | extern "C" { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | #endif |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
57 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
58 | * No buffer features enabled (all flags cleared). |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
59 | */ |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
60 | #define UCX_BUFFER_DEFAULT 0x00 |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
140
diff
changeset
|
61 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
62 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
63 | * If this flag is enabled, the buffer will automatically free its contents. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
64 | */ |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
65 | #define UCX_BUFFER_AUTOFREE 0x01 |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
140
diff
changeset
|
66 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
67 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
68 | * If this flag is enabled, the buffer will automatically extends its capacity. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
69 | */ |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
70 | #define UCX_BUFFER_AUTOEXTEND 0x02 |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
72 | /** UCX Buffer. */ |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
73 | typedef struct { |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
74 | /** A pointer to the buffer contents. */ |
76 | 75 | char *space; |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
76 | /** Current position of the buffer. */ |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
77 | size_t pos; |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
78 | /** Current capacity (i.e. maximum size) of the buffer. */ |
76 | 79 | size_t capacity; |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
80 | /** Current size of the buffer content. */ |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
81 | size_t size; |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
82 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
83 | * Flag register for buffer features. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
84 | * @see #UCX_BUFFER_DEFAULT |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
85 | * @see #UCX_BUFFER_AUTOFREE |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
86 | * @see #UCX_BUFFER_AUTOEXTEND |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
87 | */ |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
88 | int flags; |
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
89 | } UcxBuffer; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
91 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
92 | * Creates a new buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
93 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
94 | * <b>Note:</b> you may provide <code>NULL</code> as argument for |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
95 | * <code>space</code>. Then this function will allocate the space and enforce |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
96 | * the #UCX_BUFFER_AUTOFREE flag. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
97 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
98 | * @param space pointer to the memory area, or <code>NULL</code> to allocate |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
99 | * new memory |
169
279dd3ca7a77
fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
100 | * @param capacity the capacity of the buffer |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
101 | * @param flags buffer features (see UcxBuffer.flags) |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
102 | * @return the new buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
103 | */ |
169
279dd3ca7a77
fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
104 | UcxBuffer *ucx_buffer_new(void *space, size_t capacity, int flags); |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
105 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
106 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
107 | * Destroys a buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
108 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
109 | * If the #UCX_BUFFER_AUTOFREE feature is enabled, the contents of the buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
110 | * are also freed. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
111 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
112 | * @param buffer the buffer to destroy |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
113 | */ |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
114 | void ucx_buffer_free(UcxBuffer* buffer); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
116 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
117 | * Creates a new buffer and fills it with extracted content from another buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
118 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
119 | * <b>Note:</b> the #UCX_BUFFER_AUTOFREE feature is enforced for the new buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
120 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
121 | * @param src the source buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
122 | * @param start the start position of extraction |
168 | 123 | * @param length the count of bytes to extract (must not be zero) |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
124 | * @param flags feature mask for the new buffer |
163
5ec9a2ca6328
minor lexical and documentation fixes
Mike Becker <universe@uap-core.de>
parents:
146
diff
changeset
|
125 | * @return a new buffer containing the extraction |
62 | 126 | */ |
76 | 127 | UcxBuffer* ucx_buffer_extract(UcxBuffer *src, |
62 | 128 | size_t start, size_t length, int flags); |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
129 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
130 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
131 | * A shorthand macro for the full extraction of the buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
132 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
133 | * @param src the source buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
134 | * @param flags feature mask for the new buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
135 | * @return a new buffer with the extracted content |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
136 | */ |
62 | 137 | #define ucx_buffer_clone(src,flags) \ |
168 | 138 | ucx_buffer_extract(src, 0, (src)->capacity, flags) |
62 | 139 | |
290
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
140 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
141 | /** |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
142 | * Shifts the contents of the buffer by the given offset. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
143 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
144 | * If the offset is positive, the contents are shifted to the right. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
145 | * If auto extension is enabled, the buffer grows, if necessary. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
146 | * In case the auto extension fails, this function returns a non-zero value and |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
147 | * no contents are changed. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
148 | * If auto extension is disabled, the contents that do not fit into the buffer |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
149 | * are discarded. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
150 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
151 | * If the offset is negative, the contents are shifted to the left where the |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
152 | * first <code>shift</code> bytes are discarded. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
153 | * The new size of the buffer is the old size minus |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
154 | * the absolute shift value. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
155 | * If this value is larger than the buffer size, the buffer is emptied (but |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
156 | * not cleared, see the security note below). |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
157 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
158 | * The buffer position gets shifted alongside with the content but is kept |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
159 | * within the boundaries of the buffer. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
160 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
161 | * <b>Security note:</b> the shifting operation does <em>not</em> erase the |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
162 | * previously occupied memory cells. You can easily do that manually, e.g. by |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
163 | * calling <code>memset(buffer->space, 0, shift)</code> for a right shift or |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
164 | * <code>memset(buffer->size, 0, buffer->capacity-buffer->size)</code> |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
165 | * for a left shift. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
166 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
167 | * @param buffer the buffer |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
168 | * @param shift the shift offset (negative means left shift) |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
169 | * @return 0 on success, non-zero if a required auto-extension fails |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
170 | */ |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
171 | int ucx_buffer_shift(UcxBuffer* buffer, off_t shift); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
172 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
173 | /** |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
174 | * Shifts the buffer to the right. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
175 | * See ucx_buffer_shift() for details. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
176 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
177 | * @param buffer the buffer |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
178 | * @param shift the shift offset |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
179 | * @return 0 on success, non-zero if a required auto-extension fails |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
180 | * @see ucx_buffer_shift() |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
181 | */ |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
182 | int ucx_buffer_shift_right(UcxBuffer* buffer, size_t shift); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
183 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
184 | /** |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
185 | * Shifts the buffer to the left. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
186 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
187 | * See ucx_buffer_shift() for details. Note, however, that this method expects |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
188 | * a positive shift offset. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
189 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
190 | * Since a left shift cannot fail due to memory allocation problems, this |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
191 | * function always returns zero. |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
192 | * |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
193 | * @param buffer the buffer |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
194 | * @param shift the shift offset |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
195 | * @return always zero |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
196 | * @see ucx_buffer_shift() |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
197 | */ |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
198 | int ucx_buffer_shift_left(UcxBuffer* buffer, size_t shift); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
199 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
200 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
201 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
202 | * Moves the position of the buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
203 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
204 | * The new position is relative to the <code>whence</code> argument. |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | * |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
206 | * SEEK_SET marks the start of the buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
207 | * SEEK_CUR marks the current position. |
165
4d85da1f98db
hotfix for ucx_buffer_seek documentation
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
208 | * SEEK_END marks the end of the buffer. |
4d85da1f98db
hotfix for ucx_buffer_seek documentation
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
209 | * |
4d85da1f98db
hotfix for ucx_buffer_seek documentation
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
210 | * With an offset of zero, this function sets the buffer position to zero |
4d85da1f98db
hotfix for ucx_buffer_seek documentation
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
211 | * (SEEK_SET), the buffer size (SEEK_END) or leaves the buffer position |
4d85da1f98db
hotfix for ucx_buffer_seek documentation
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
212 | * unchanged (SEEK_CUR). |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
213 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
214 | * @param buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
215 | * @param offset position offset relative to <code>whence</code> |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
216 | * @param whence one of SEEK_SET, SEEK_CUR or SEEK_END |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
217 | * @return 0 on success, non-zero if the position is invalid |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | */ |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
220 | int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
222 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
223 | * Clears the buffer by resetting the position and deleting the data. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
224 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
225 | * The data is deleted by a zeroing it with call to <code>memset()</code>. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
226 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
227 | * @param buffer the buffer to be cleared |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
228 | */ |
289
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
229 | #define ucx_buffer_clear(buffer) memset((buffer)->space, 0, (buffer)->size); \ |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
230 | (buffer)->size = 0; (buffer)->pos = 0; |
85
0ef0df7aa2c2
fixed comments + added ucx_buffer_clear
Mike Becker <universe@uap-core.de>
parents:
81
diff
changeset
|
231 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
232 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
233 | * Tests, if the buffer position has exceeded the buffer capacity. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
234 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
235 | * @param buffer the buffer to test |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
236 | * @return non-zero, if the current buffer position has exceeded the last |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
237 | * available byte of the buffer. |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | */ |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
239 | int ucx_buffer_eof(UcxBuffer *buffer); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | |
76 | 241 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
242 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
243 | * Extends the capacity of the buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
244 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
245 | * <b>Note:</b> The buffer capacity increased by a power of two. I.e. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
246 | * the buffer capacity is doubled, as long as it would not hold the current |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
247 | * content plus the additional required bytes. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
248 | * |
168 | 249 | * <b>Attention:</b> the argument provided is the number of <i>additional</i> |
250 | * bytes the buffer shall hold. It is <b>NOT</b> the total number of bytes the | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
251 | * buffer shall hold. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
252 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
253 | * @param buffer the buffer to extend |
168 | 254 | * @param additional_bytes the number of additional bytes the buffer shall |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
255 | * <i>at least</i> hold |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
256 | * @return 0 on success or a non-zero value on failure |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
257 | */ |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
258 | int ucx_buffer_extend(UcxBuffer *buffer, size_t additional_bytes); |
76 | 259 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
260 | /** |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
215
diff
changeset
|
261 | * Writes data to a UcxBuffer. |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
262 | * |
215
e0853e077770
removed some implementation details from documentation + fixed ucx_buffer_write doc
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
263 | * The position of the buffer is increased by the number of bytes written. |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
264 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
265 | * @param ptr a pointer to the memory area containing the bytes to be written |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
266 | * @param size the length of one element |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
267 | * @param nitems the element count |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
268 | * @param buffer the UcxBuffer to write to |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
269 | * @return the total count of bytes written |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
270 | */ |
76 | 271 | size_t ucx_buffer_write(const void *ptr, size_t size, size_t nitems, |
272 | UcxBuffer *buffer); | |
273 | ||
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
274 | /** |
225
a1a068c2c4ef
updates documenting comments
Mike Becker <universe@uap-core.de>
parents:
215
diff
changeset
|
275 | * Reads data from a UcxBuffer. |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
276 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
277 | * The position of the buffer is increased by the number of bytes read. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
278 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
279 | * @param ptr a pointer to the memory area where to store the read data |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
280 | * @param size the length of one element |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
281 | * @param nitems the element count |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
282 | * @param buffer the UcxBuffer to read from |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
165
diff
changeset
|
283 | * @return the total number of elements read |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
284 | */ |
76 | 285 | size_t ucx_buffer_read(void *ptr, size_t size, size_t nitems, |
286 | UcxBuffer *buffer); | |
287 | ||
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
288 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
289 | * Writes a character to a buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
290 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
291 | * The least significant byte of the argument is written to the buffer. If the |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
292 | * end of the buffer is reached and #UCX_BUFFER_AUTOEXTEND feature is enabled, |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
293 | * the buffer capacity is extended by ucx_buffer_extend(). If the feature is |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
294 | * disabled or buffer extension fails, <code>EOF</code> is returned. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
295 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
296 | * On successful write the position of the buffer is increased. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
297 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
298 | * @param buffer the buffer to write to |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
299 | * @param c the character to write as <code>int</code> value |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
300 | * @return the byte that has bean written as <code>int</code> value or |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
301 | * <code>EOF</code> when the end of the stream is reached and automatic |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
302 | * extension is not enabled or not possible |
76 | 303 | */ |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
304 | int ucx_buffer_putc(UcxBuffer *buffer, int c); |
76 | 305 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
306 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
307 | * Gets a character from a buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
308 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
309 | * The current position of the buffer is increased after a successful read. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
310 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
311 | * @param buffer the buffer to read from |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
312 | * @return the character as <code>int</code> value or <code>EOF</code>, if the |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
313 | * end of the buffer is reached |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
314 | */ |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
315 | int ucx_buffer_getc(UcxBuffer *buffer); |
76 | 316 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
317 | /** |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
318 | * Writes a string to a buffer. |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
319 | * |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
320 | * @param buffer the buffer |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
321 | * @param str the string |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
322 | * @return the number of bytes written |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
323 | */ |
290
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
289
diff
changeset
|
324 | size_t ucx_buffer_puts(UcxBuffer *buffer, const char *str); |
86
55bf819cbc88
added generic ncopy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
85
diff
changeset
|
325 | |
289
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
326 | /** |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
327 | * Returns the complete buffer content as sstr_t. |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
328 | * @param buffer the buffer |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
329 | * @return the result of <code>sstrn()</code> with the buffer space and size |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
330 | * as arguments |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
331 | */ |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
332 | #define ucx_buffer_to_sstr(buffer) sstrn((buffer)->space, (buffer)->size) |
a5eabd407774
adds ucx_buffer_to_sstr() macro
Mike Becker <universe@uap-core.de>
parents:
259
diff
changeset
|
333 | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | #ifdef __cplusplus |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | #endif |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | |
120 | 338 | #endif /* UCX_BUFFER_H */ |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 |