Fri, 19 Dec 2025 17:53:18 +0100
update ucx
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | /** |
| 852 | 30 | * @file buffer.h |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | * |
| 852 | 32 | * @brief Advanced buffer implementation. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | * Instances of CxBuffer can be used to read from or to write to like one |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | * would do with a stream. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | * Some features for convenient use of the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | * can be enabled. See the documentation of the macro constants for more |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | * information. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | * |
| 852 | 41 | * @author Mike Becker |
| 42 | * @author Olaf Wintermann | |
| 43 | * @copyright 2-Clause BSD License | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #ifndef UCX_BUFFER_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | #define UCX_BUFFER_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #include "common.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | #include "allocator.h" |
| 891 | 51 | #include "string.h" |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
| 852 | 53 | #ifdef __cplusplus |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | extern "C" { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | * No buffer features enabled (all flags cleared). |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | #define CX_BUFFER_DEFAULT 0x00 |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | * If this flag is enabled, the buffer will automatically free its contents when destroyed. |
| 852 | 64 | * |
| 65 | * Do NOT set this flag together with #CX_BUFFER_COPY_ON_WRITE. It will be automatically | |
| 889 | 66 | * set when the copy-on-write operation is performed. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | #define CX_BUFFER_FREE_CONTENTS 0x01 |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | /** |
| 852 | 71 | * If this flag is enabled, the buffer will automatically extend its capacity. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | #define CX_BUFFER_AUTO_EXTEND 0x02 |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
| 852 | 75 | /** |
| 76 | * If this flag is enabled, the buffer will allocate new memory when written to. | |
| 77 | * | |
| 889 | 78 | * The current contents of the buffer will be copied to the new memory, and the flag |
| 852 | 79 | * will be cleared while the #CX_BUFFER_FREE_CONTENTS flag will be set automatically. |
| 80 | */ | |
| 81 | #define CX_BUFFER_COPY_ON_WRITE 0x04 | |
| 82 | ||
| 83 | /** | |
| 84 | * If this flag is enabled, the buffer will copy its contents to a new memory area on reallocation. | |
| 85 | * | |
| 86 | * After performing the copy, the flag is automatically cleared. | |
| 87 | * This flag has no effect on buffers which do not have #CX_BUFFER_AUTO_EXTEND set, which is why | |
| 88 | * buffers automatically admit the auto-extend flag when initialized with copy-on-extend enabled. | |
| 89 | */ | |
| 90 | #define CX_BUFFER_COPY_ON_EXTEND 0x08 | |
| 91 | ||
| 92 | /** | |
| 891 | 93 | * If this flag is enabled, the buffer will never free its contents regardless of #CX_BUFFER_FREE_CONTENTS. |
| 94 | * | |
| 95 | * This is useful, for example, when you want to keep a pointer to the data after destroying the buffer. | |
| 96 | */ | |
| 97 | #define CX_BUFFER_DO_NOT_FREE 0x10 | |
| 98 | ||
| 99 | /** | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
100 | * Function pointer for cxBufferWrite that is compatible with cx_write_func. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
101 | * @see cx_write_func |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
102 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
103 | #define cxBufferWriteFunc ((cx_write_func) cxBufferWrite) |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
104 | /** |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
105 | * Function pointer for cxBufferRead that is compatible with cx_read_func. |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
106 | * @see cx_read_func |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
107 | */ |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
108 | #define cxBufferReadFunc ((cx_read_func) cxBufferRead) |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
109 | |
| 852 | 110 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | /** Structure for the UCX buffer data. */ |
| 852 | 112 | struct cx_buffer_s { |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | /** A pointer to the buffer contents. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | union { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | * Data is interpreted as text. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | char *space; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | * Data is interpreted as binary. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | unsigned char *bytes; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | /** The allocator to use for automatic memory management. */ |
| 852 | 125 | const CxAllocator *allocator; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | /** Current position of the buffer. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | size_t pos; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | /** Current capacity (i.e. maximum size) of the buffer. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | size_t capacity; |
| 891 | 130 | /** Maximum capacity that this buffer may grow to. */ |
| 131 | size_t max_capacity; | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | /** Current size of the buffer content. */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | size_t size; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | * Flag register for buffer features. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | * @see #CX_BUFFER_DEFAULT |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | * @see #CX_BUFFER_FREE_CONTENTS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | * @see #CX_BUFFER_AUTO_EXTEND |
| 852 | 139 | * @see #CX_BUFFER_COPY_ON_WRITE |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | int flags; |
| 852 | 142 | }; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | * UCX buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | */ |
| 852 | 147 | typedef struct cx_buffer_s CxBuffer; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | * Initializes a fresh buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | * |
| 852 | 152 | * You may also provide a read-only @p space, in which case |
| 153 | * you will need to cast the pointer, and you should set the | |
| 154 | * #CX_BUFFER_COPY_ON_WRITE flag. | |
| 155 | * | |
| 889 | 156 | * You need to set the size manually after initialization if |
| 852 | 157 | * you provide @p space which already contains data. |
| 158 | * | |
| 159 | * When you specify stack memory as @p space and decide to use | |
| 160 | * the auto-extension feature, you @em must use the | |
| 161 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the | |
| 162 | * #CX_BUFFER_AUTO_EXTEND flag. | |
| 163 | * | |
| 889 | 164 | * @note You may provide @c NULL as the argument for @p space. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | * Then this function will allocate the space and enforce |
| 852 | 166 | * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying |
| 167 | * copy-on-write should be avoided, because the allocated | |
| 168 | * space will be leaking after the copy-on-write operation. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | * @param buffer the buffer to initialize |
| 891 | 171 | * @param allocator the allocator this buffer shall use for automatic |
| 172 | * memory management | |
| 173 | * (if @c NULL, the cxDefaultAllocator will be used) | |
| 852 | 174 | * @param space pointer to the memory area, or @c NULL to allocate |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | * new memory |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | * @param capacity the capacity of the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | * @param flags buffer features (see cx_buffer_s.flags) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | * @return zero on success, non-zero if a required allocation failed |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | */ |
| 852 | 180 | cx_attr_nonnull_arg(1) |
| 891 | 181 | CX_EXPORT int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator, |
| 182 | void *space, size_t capacity, int flags); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | * Destroys the buffer contents. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | * If you want to free the memory of the entire buffer, use cxBufferFree(). |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | * @param buffer the buffer which contents shall be destroyed |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | * @see cxBufferInit() |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | */ |
| 852 | 193 | cx_attr_nonnull |
| 889 | 194 | CX_EXPORT void cxBufferDestroy(CxBuffer *buffer); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | * Deallocates the buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys |
| 852 | 200 | * the contents. If you @em only want to destroy the contents, use cxBufferDestroy(). |
| 201 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | * @param buffer the buffer to deallocate |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | * @see cxBufferCreate() |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | */ |
| 889 | 205 | CX_EXPORT void cxBufferFree(CxBuffer *buffer); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | /** |
| 852 | 208 | * Allocates and initializes a fresh buffer. |
| 209 | * | |
| 210 | * You may also provide a read-only @p space, in which case | |
| 211 | * you will need to cast the pointer, and you should set the | |
| 212 | * #CX_BUFFER_COPY_ON_WRITE flag. | |
| 213 | * When you specify stack memory as @p space and decide to use | |
| 214 | * the auto-extension feature, you @em must use the | |
| 215 | * #CX_BUFFER_COPY_ON_EXTEND flag, instead of the | |
| 216 | * #CX_BUFFER_AUTO_EXTEND flag. | |
| 217 | * | |
| 889 | 218 | * @note You may provide @c NULL as the argument for @p space. |
| 852 | 219 | * Then this function will allocate the space and enforce |
| 220 | * the #CX_BUFFER_FREE_CONTENTS flag. | |
| 221 | * | |
| 891 | 222 | * @param allocator the allocator to use for allocating the structure and the automatic |
| 223 | * memory management within the buffer | |
| 224 | * (if @c NULL, the cxDefaultAllocator will be used) | |
| 852 | 225 | * @param space pointer to the memory area, or @c NULL to allocate |
| 226 | * new memory | |
| 227 | * @param capacity the capacity of the buffer | |
| 228 | * @param flags buffer features (see cx_buffer_s.flags) | |
| 229 | * @return a pointer to the buffer on success, @c NULL if a required allocation failed | |
| 230 | */ | |
| 889 | 231 | cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard |
| 891 | 232 | CX_EXPORT CxBuffer *cxBufferCreate(const CxAllocator *allocator, void *space, |
| 233 | size_t capacity, int flags); | |
| 852 | 234 | |
| 235 | /** | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | * Shifts the contents of the buffer by the given offset. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | * If the offset is positive, the contents are shifted to the right. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | * If auto extension is enabled, the buffer grows, if necessary. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | * In case the auto extension fails, this function returns a non-zero value and |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | * no contents are changed. |
| 889 | 242 | * When the auto extension is disabled, the contents that do not fit into the |
| 243 | * buffer are discarded. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * If the offset is negative, the contents are shifted to the left where the |
| 852 | 246 | * first @p shift bytes are discarded. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | * The new size of the buffer is the old size minus the absolute shift value. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | * If this value is larger than the buffer size, the buffer is emptied (but |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | * not cleared, see the security note below). |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | * |
| 889 | 251 | * The buffer position gets shifted alongside the content but is kept |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | * within the boundaries of the buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | * |
| 852 | 254 | * @note For situations where @c off_t is not large enough, there are specialized cxBufferShiftLeft() and |
| 889 | 255 | * cxBufferShiftRight() functions using a @c size_t as the parameter type. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | * |
| 852 | 257 | * @attention |
| 258 | * Security Note: The shifting operation does @em not erase the previously occupied memory cells. | |
| 889 | 259 | * But you can do that manually by calling |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code> |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | * for a left shift. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | * @param buffer the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | * @param shift the shift offset (negative means left shift) |
| 852 | 266 | * @retval zero success |
| 267 | * @retval non-zero if a required auto-extension or copy-on-write fails | |
| 268 | * @see cxBufferShiftLeft() | |
| 269 | * @see cxBufferShiftRight() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | */ |
| 852 | 271 | cx_attr_nonnull |
| 889 | 272 | CX_EXPORT int cxBufferShift(CxBuffer *buffer, off_t shift); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | * Shifts the buffer to the right. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | * See cxBufferShift() for details. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | * @param buffer the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | * @param shift the shift offset |
| 852 | 280 | * @retval zero success |
| 281 | * @retval non-zero if a required auto-extension or copy-on-write fails | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | * @see cxBufferShift() |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | */ |
| 852 | 284 | cx_attr_nonnull |
| 889 | 285 | CX_EXPORT int cxBufferShiftRight(CxBuffer *buffer, size_t shift); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | * Shifts the buffer to the left. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | * See cxBufferShift() for details. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | * @param buffer the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | * @param shift the positive shift offset |
| 852 | 293 | * @retval zero success |
| 294 | * @retval non-zero if the buffer uses copy-on-write and the allocation fails | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | * @see cxBufferShift() |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | */ |
| 852 | 297 | cx_attr_nonnull |
| 889 | 298 | CX_EXPORT int cxBufferShiftLeft(CxBuffer *buffer, size_t shift); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | * Moves the position of the buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | * |
| 852 | 304 | * The new position is relative to the @p whence argument. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | * |
| 852 | 306 | * @li @c SEEK_SET marks the start of the buffer. |
| 307 | * @li @c SEEK_CUR marks the current position. | |
| 308 | * @li @c SEEK_END marks the end of the buffer. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | * With an offset of zero, this function sets the buffer position to zero |
| 852 | 311 | * (@c SEEK_SET), the buffer size (@c SEEK_END) or leaves the buffer position |
| 312 | * unchanged (@c SEEK_CUR). | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | * @param buffer the buffer |
| 852 | 315 | * @param offset position offset relative to @p whence |
| 316 | * @param whence one of @c SEEK_SET, @c SEEK_CUR or @c SEEK_END | |
| 317 | * @retval zero success | |
| 318 | * @retval non-zero if the position is invalid | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | */ |
| 852 | 321 | cx_attr_nonnull |
| 889 | 322 | CX_EXPORT int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | /** |
| 891 | 325 | * Discards items from the end of the buffer. |
| 326 | * | |
| 327 | * When the current position points to a byte that gets discarded, | |
| 328 | * the position is set to the buffer size. | |
| 329 | * | |
| 330 | * @param buffer the buffer | |
| 331 | * @param size the size of one item | |
| 332 | * @param nitems the number of items to discard | |
| 333 | * @return the actual number of discarded items | |
| 334 | */ | |
| 335 | cx_attr_nonnull | |
| 336 | CX_EXPORT size_t cxBufferPop(CxBuffer *buffer, size_t size, size_t nitems); | |
| 337 | ||
| 338 | /** | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | * Clears the buffer by resetting the position and deleting the data. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | * The data is deleted by zeroing it with a call to memset(). |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
342 | * If you do not need that, you can use the faster cxBufferReset(). |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | * |
| 852 | 344 | * @note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function |
| 345 | * will not erase the data and behave exactly as cxBufferReset(). | |
| 346 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | * @param buffer the buffer to be cleared |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
348 | * @see cxBufferReset() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | */ |
| 852 | 350 | cx_attr_nonnull |
| 889 | 351 | CX_EXPORT void cxBufferClear(CxBuffer *buffer); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | /** |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
354 | * Resets the buffer by resetting the position and size to zero. |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
355 | * |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
356 | * The data in the buffer is not deleted. If you need a safe |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
357 | * reset of the buffer, use cxBufferClear(). |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
358 | * |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
359 | * @param buffer the buffer to be cleared |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
360 | * @see cxBufferClear() |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
361 | */ |
| 852 | 362 | cx_attr_nonnull |
| 889 | 363 | CX_EXPORT void cxBufferReset(CxBuffer *buffer); |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
364 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
365 | /** |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
366 | * Tests, if the buffer position has exceeded the buffer size. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | * @param buffer the buffer to test |
| 852 | 369 | * @retval true if the current buffer position has exceeded the last |
| 370 | * byte of the buffer's contents | |
| 371 | * @retval false otherwise | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | */ |
| 889 | 373 | cx_attr_nonnull cx_attr_nodiscard |
| 374 | CX_EXPORT bool cxBufferEof(const CxBuffer *buffer); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | |
| 891 | 376 | /** |
| 377 | * Ensures that the buffer has the required capacity. | |
| 378 | * | |
| 379 | * If the current capacity is not sufficient, the buffer will be extended. | |
| 380 | * If the current capacity is larger, the buffer is shrunk and superfluous | |
| 381 | * content is discarded. | |
| 382 | * | |
| 383 | * This function will reserve no more bytes than requested, in contrast to | |
| 384 | * cxBufferMinimumCapacity(), which may reserve more bytes to improve the | |
| 385 | * number of future necessary reallocations. | |
| 386 | * | |
| 387 | * @param buffer the buffer | |
| 388 | * @param capacity the required capacity for this buffer | |
| 389 | * @retval zero on success | |
| 390 | * @retval non-zero on allocation failure | |
| 391 | * @see cxBufferShrink() | |
| 392 | * @see cxBufferMinimumCapacity() | |
| 393 | */ | |
| 394 | cx_attr_nonnull | |
| 395 | CX_EXPORT int cxBufferReserve(CxBuffer *buffer, size_t capacity); | |
| 396 | ||
| 397 | /** | |
| 398 | * Limits the buffer's capacity. | |
| 399 | * | |
| 400 | * If the current capacity is already larger, this function fails and returns | |
| 401 | * non-zero. | |
| 402 | * | |
| 403 | * The capacity limit will affect auto-extension features, as well as future | |
| 404 | * calls to cxBufferMinimumCapacity() and cxBufferReserve(). | |
| 405 | * | |
| 406 | * @param buffer the buffer | |
| 407 | * @param capacity the maximum allowed capacity for this buffer | |
| 408 | * @retval zero the limit is applied | |
| 409 | * @retval non-zero the new limit is smaller than the current capacity | |
| 410 | * @see cxBufferReserve() | |
| 411 | * @see cxBufferMinimumCapacity() | |
| 412 | */ | |
| 413 | cx_attr_nonnull | |
| 414 | CX_EXPORT int cxBufferMaximumCapacity(CxBuffer *buffer, size_t capacity); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | * Ensures that the buffer has a minimum capacity. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | * |
| 891 | 419 | * If the current capacity is not sufficient, the buffer will be generously |
| 420 | * extended. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | * |
| 886 | 422 | * The new capacity will be a power of two until the system's page size is reached. |
| 423 | * Then, the new capacity will be a multiple of the page size. | |
| 424 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | * @param buffer the buffer |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | * @param capacity the minimum required capacity for this buffer |
| 852 | 427 | * @retval zero the capacity was already sufficient or successfully increased |
| 428 | * @retval non-zero on allocation failure | |
| 891 | 429 | * @see cxBufferMaximumCapacity() |
| 430 | * @see cxBufferReserve() | |
| 886 | 431 | * @see cxBufferShrink() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | */ |
| 852 | 433 | cx_attr_nonnull |
| 889 | 434 | CX_EXPORT int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | /** |
| 886 | 437 | * Shrinks the capacity of the buffer to fit its current size. |
| 438 | * | |
| 439 | * If @p reserve is larger than zero, the buffer is shrunk to its size plus | |
| 440 | * the number of reserved bytes. | |
| 441 | * | |
| 442 | * If the current capacity is not larger than the size plus the reserved bytes, | |
| 443 | * nothing happens. | |
| 444 | * | |
| 445 | * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set, | |
| 446 | * this function does nothing. | |
| 447 | * | |
| 448 | * @param buffer the buffer | |
| 449 | * @param reserve the number of bytes that shall remain reserved | |
| 891 | 450 | * @see cxBufferReserve() |
| 886 | 451 | * @see cxBufferMinimumCapacity() |
| 452 | */ | |
| 453 | cx_attr_nonnull | |
| 889 | 454 | CX_EXPORT void cxBufferShrink(CxBuffer *buffer, size_t reserve); |
| 886 | 455 | |
| 456 | /** | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | * Writes data to a CxBuffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | * |
| 891 | 459 | * If auto-extension is enabled, the buffer's capacity is automatically |
| 460 | * increased when it is not large enough to hold all data. | |
| 461 | * By default, the capacity grows indefinitely, unless limited with | |
| 462 | * cxBufferMaximumCapacity(). | |
| 463 | * When auto-extension fails, this function writes no data and returns zero. | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
464 | * |
| 891 | 465 | * The position of the buffer is moved alongside the written data. |
| 852 | 466 | * |
| 467 | * @note The signature is compatible with the fwrite() family of functions. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | * |
| 852 | 469 | * @param ptr a pointer to the memory area containing the bytes to be written |
| 470 | * @param size the length of one element | |
| 471 | * @param nitems the element count | |
| 472 | * @param buffer the CxBuffer to write to | |
| 473 | * @return the total count of elements written | |
| 474 | * @see cxBufferAppend() | |
| 475 | * @see cxBufferRead() | |
| 476 | */ | |
| 477 | cx_attr_nonnull | |
| 889 | 478 | CX_EXPORT size_t cxBufferWrite(const void *ptr, size_t size, |
| 479 | size_t nitems, CxBuffer *buffer); | |
| 852 | 480 | |
| 481 | /** | |
| 482 | * Appends data to a CxBuffer. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | * |
| 852 | 484 | * The data is always appended to current data within the buffer, |
| 485 | * regardless of the current position. | |
| 486 | * This is especially useful when the buffer is primarily meant for reading | |
| 487 | * while additional data is added to the buffer occasionally. | |
| 488 | * Consequently, the position of the buffer is unchanged after this operation. | |
| 489 | * | |
| 490 | * @note The signature is compatible with the fwrite() family of functions. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 | * @param ptr a pointer to the memory area containing the bytes to be written |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493 | * @param size the length of one element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494 | * @param nitems the element count |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495 | * @param buffer the CxBuffer to write to |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496 | * @return the total count of elements written |
| 852 | 497 | * @see cxBufferWrite() |
| 498 | * @see cxBufferRead() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | */ |
| 852 | 500 | cx_attr_nonnull |
| 889 | 501 | CX_EXPORT size_t cxBufferAppend(const void *ptr, size_t size, |
| 502 | size_t nitems, CxBuffer *buffer); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | * Reads data from a CxBuffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | * The position of the buffer is increased by the number of bytes read. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | * |
| 852 | 509 | * @note The signature is compatible with the fread() family of functions. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | * @param ptr a pointer to the memory area where to store the read data |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | * @param size the length of one element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | * @param nitems the element count |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | * @param buffer the CxBuffer to read from |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | * @return the total number of elements read |
| 852 | 516 | * @see cxBufferWrite() |
| 517 | * @see cxBufferAppend() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | */ |
| 852 | 519 | cx_attr_nonnull |
| 889 | 520 | CX_EXPORT size_t cxBufferRead(void *ptr, size_t size, |
| 521 | size_t nitems, CxBuffer *buffer); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | * Writes a character to a buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | * The least significant byte of the argument is written to the buffer. If the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527 | * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled, |
| 891 | 528 | * the buffer capacity is extended, unless a limit set by |
| 529 | * cxBufferMaximumCapacity() is reached. | |
| 530 | * If the feature is disabled or the buffer extension fails, @c EOF is returned. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | * |
| 889 | 532 | * On successful writing, the position of the buffer is increased. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533 | * |
| 852 | 534 | * If you just want to write a null-terminator at the current position, you |
| 535 | * should use cxBufferTerminate() instead. | |
| 536 | * | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537 | * @param buffer the buffer to write to |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538 | * @param c the character to write |
| 891 | 539 | * @return the byte that has been written or @c EOF when the end of the |
| 540 | * stream is reached, and automatic extension is not enabled or not possible | |
| 852 | 541 | * @see cxBufferTerminate() |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
542 | */ |
| 852 | 543 | cx_attr_nonnull |
| 889 | 544 | CX_EXPORT int cxBufferPut(CxBuffer *buffer, int c); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546 | /** |
| 852 | 547 | * Writes a terminating zero to a buffer at the current position. |
| 548 | * | |
| 891 | 549 | * If successful, also sets the size to the current position and shrinks the buffer. |
| 852 | 550 | * |
| 551 | * The purpose of this function is to have the written data ready to be used as | |
| 886 | 552 | * a C string with the buffer's size being the length of that string. |
| 852 | 553 | * |
| 554 | * @param buffer the buffer to write to | |
| 555 | * @return zero, if the terminator could be written, non-zero otherwise | |
| 891 | 556 | * @see cxBufferShrink() |
| 852 | 557 | */ |
| 558 | cx_attr_nonnull | |
| 889 | 559 | CX_EXPORT int cxBufferTerminate(CxBuffer *buffer); |
| 852 | 560 | |
| 561 | /** | |
| 891 | 562 | * Internal function - do not use. |
| 852 | 563 | * |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564 | * @param buffer the buffer |
| 891 | 565 | * @param str the string |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | * @return the number of bytes written |
| 891 | 567 | * @see cxBufferPutString() |
| 568 | */ | |
| 569 | cx_attr_nonnull | |
| 570 | CX_EXPORT size_t cx_buffer_put_string(CxBuffer *buffer, cxstring str); | |
| 571 | ||
| 572 | /** | |
| 573 | * Writes a string to a buffer with cxBufferWrite(). | |
| 574 | * | |
| 575 | * @param buffer (@c CxBuffer*) the buffer | |
| 576 | * @param str (any string) the zero-terminated string | |
| 577 | * @return (@c size_t) the number of bytes written | |
| 578 | * @see cxBufferWrite() | |
| 579 | * @see cx_strcast() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | */ |
| 891 | 581 | #define cxBufferPutString(buffer, str) cx_buffer_put_string(buffer, cx_strcast(str)) |
| 582 | ||
| 583 | /** | |
| 584 | * Internal function - do not use. | |
| 585 | * | |
| 586 | * @param buffer the buffer | |
| 587 | * @param str the string | |
| 588 | * @return the number of bytes written | |
| 589 | * @see cxBufferPutString() | |
| 590 | */ | |
| 591 | cx_attr_nonnull | |
| 592 | CX_EXPORT size_t cx_buffer_append_string(CxBuffer *buffer, cxstring str); | |
| 593 | ||
| 594 | /** | |
| 595 | * Appends a string to a buffer with cxBufferAppend(). | |
| 596 | * | |
| 597 | * @param buffer (@c CxBuffer*) the buffer | |
| 598 | * @param str (any string) the zero-terminated string | |
| 599 | * @return (@c size_t) the number of bytes written | |
| 600 | * @see cxBufferAppend() | |
| 601 | * @see cx_strcast() | |
| 602 | */ | |
| 603 | #define cxBufferAppendString(buffer, str) cx_buffer_append_string(buffer, cx_strcast(str)) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606 | * Gets a character from a buffer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | * The current position of the buffer is increased after a successful read. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | * @param buffer the buffer to read from |
| 852 | 611 | * @return the character or @c EOF, if the end of the buffer is reached |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612 | */ |
| 852 | 613 | cx_attr_nonnull |
| 889 | 614 | CX_EXPORT int cxBufferGet(CxBuffer *buffer); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617 | } |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620 | #endif // UCX_BUFFER_H |