src/cx/buffer.h

Thu, 19 Dec 2024 12:00:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 19 Dec 2024 12:00:20 +0100
changeset 1027
b1373253e202
parent 1024
8f99f6c28bd3
child 1028
3e4905241838
permissions
-rw-r--r--

add CHANGELOG entry for issue #431

483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 * \file buffer.h
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 * \brief Advanced buffer implementation.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 * Instances of CxBuffer can be used to read from or to write to like one
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 * would do with a stream.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 * Some features for convenient use of the buffer
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 * can be enabled. See the documentation of the macro constants for more
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 * information.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 * \author Mike Becker
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 * \author Olaf Wintermann
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 * \copyright 2-Clause BSD License
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #ifndef UCX_BUFFER_H
484
9e6900b1cf9d add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents: 483
diff changeset
47 #define UCX_BUFFER_H
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48
484
9e6900b1cf9d add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents: 483
diff changeset
49 #include "common.h"
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
50 #include "allocator.h"
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
52 #ifdef __cplusplus
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 extern "C" {
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 #endif
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 * No buffer features enabled (all flags cleared).
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 #define CX_BUFFER_DEFAULT 0x00
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 * If this flag is enabled, the buffer will automatically free its contents when destroyed.
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
63 *
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
64 * Do NOT set this flag together with #CX_BUFFER_COPY_ON_WRITE. It will be automatically
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
65 * set when the copy-on-write operations is performed.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 #define CX_BUFFER_FREE_CONTENTS 0x01
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 /**
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
70 * If this flag is enabled, the buffer will automatically extend its capacity.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 #define CX_BUFFER_AUTO_EXTEND 0x02
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
74 /**
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
75 * If this flag is enabled, the buffer will allocate new memory when written to.
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
76 *
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
77 * The current contents of the buffer will be copied to the new memory and the flag
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
78 * will be cleared while the #CX_BUFFER_FREE_CONTENTS flag will be set automatically.
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
79 */
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
80 #define CX_BUFFER_COPY_ON_WRITE 0x04
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
81
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 /** Structure for the UCX buffer data. */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 typedef struct {
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 /** A pointer to the buffer contents. */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 union {
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 * Data is interpreted as text.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 char *space;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 * Data is interpreted as binary.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 unsigned char *bytes;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 };
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
95 /** The allocator to use for automatic memory management. */
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
96 const CxAllocator *allocator;
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 /** Current position of the buffer. */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 size_t pos;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 /** Current capacity (i.e. maximum size) of the buffer. */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 size_t capacity;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 /** Current size of the buffer content. */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 size_t size;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 /**
539
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
104 * The buffer may not extend beyond this threshold before starting to flush.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
105 * Default is \c SIZE_MAX (flushing disabled when auto extension is enabled).
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
106 */
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
107 size_t flush_threshold;
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
108 /**
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
109 * The block size for the elements to flush.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
110 * Default is 4096 bytes.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
111 */
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
112 size_t flush_blksize;
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
113 /**
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
114 * The maximum number of blocks to flush in one cycle.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
115 * Zero disables flushing entirely (this is the default).
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
116 * Set this to \c SIZE_MAX to flush the entire buffer.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
117 *
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
118 * @attention if the maximum number of blocks multiplied with the block size
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
119 * is smaller than the expected contents written to this buffer within one write
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
120 * operation, multiple flush cycles are performed after that write.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
121 * That means the total number of blocks flushed after one write to this buffer may
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
122 * be larger than \c flush_blkmax.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
123 */
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
124 size_t flush_blkmax;
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
125
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
126 /**
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
127 * The write function used for flushing.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
128 * If NULL, the flushed content gets discarded.
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
129 */
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 541
diff changeset
130 cx_write_func flush_func;
539
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
131
9cd98da9ee17 #184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents: 537
diff changeset
132 /**
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
133 * The target for \c flush_func.
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
134 */
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
135 void *flush_target;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
136
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
137 /**
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 * Flag register for buffer features.
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
139 * @see #CX_BUFFER_DEFAULT
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
140 * @see #CX_BUFFER_FREE_CONTENTS
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
141 * @see #CX_BUFFER_AUTO_EXTEND
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
142 * @see #CX_BUFFER_COPY_ON_WRITE
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 */
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 int flags;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 } cx_buffer_s;
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 * UCX buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
150 typedef cx_buffer_s CxBuffer;
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 /**
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
153 * Initializes a fresh buffer.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 *
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
155 * You may also provide a read-only \p space, in which case
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
156 * you will need to cast the pointer, and you should set the
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
157 * #CX_BUFFER_COPY_ON_WRITE flag.
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
158 *
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 * \note You may provide \c NULL as argument for \p space.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 * Then this function will allocate the space and enforce
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
161 * the #CX_BUFFER_FREE_CONTENTS flag. In that case, specifying
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
162 * copy-on-write should be avoided, because the allocated
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
163 * space will be leaking after the copy-on-write operation.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 *
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
165 * @param buffer the buffer to initialize
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
166 * @param space pointer to the memory area, or \c NULL to allocate
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 * new memory
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
168 * @param capacity the capacity of the buffer
673
60fb6aec157d make allocator in cxBufferInit optional
Mike Becker <universe@uap-core.de>
parents: 628
diff changeset
169 * @param allocator the allocator this buffer shall use for automatic
989
8aa57a7fecc4 improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
170 * memory management
8aa57a7fecc4 improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
171 * (if \c NULL, a default stdlib allocator will be used)
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
172 * @param flags buffer features (see cx_buffer_s.flags)
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
173 * @return zero on success, non-zero if a required allocation failed
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
175 cx_attr_nonnull_arg(1)
501
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
176 int cxBufferInit(
9a08f5e515cc add allocator support to CxBuffer
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
177 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 void *space,
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 size_t capacity,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
180 const CxAllocator *allocator,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 int flags
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 /**
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
185 * Destroys the buffer contents.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
186 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
187 * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
188 * If you want to free the memory of the entire buffer, use cxBufferFree().
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
189 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
190 * @param buffer the buffer which contents shall be destroyed
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
191 * @see cxBufferInit()
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
192 */
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
193 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
194 void cxBufferDestroy(CxBuffer *buffer);
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
195
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
196 /**
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
197 * Deallocates the buffer.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
198 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
199 * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, this function also destroys
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
200 * the contents. If you \em only want to destroy the contents, use cxBufferDestroy().
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
201 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
202 * \remark As with all free() functions, this accepts \c NULL arguments in which
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
203 * case it does nothing.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
204 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
205 * @param buffer the buffer to deallocate
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
206 * @see cxBufferCreate()
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
207 */
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
208 void cxBufferFree(CxBuffer *buffer);
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
209
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
210 /**
683
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
211 * Allocates and initializes a fresh buffer.
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
212 *
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
213 * You may also provide a read-only \p space, in which case
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
214 * you will need to cast the pointer, and you should set the
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
215 * #CX_BUFFER_COPY_ON_WRITE flag.
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
216 *
683
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
217 * \note You may provide \c NULL as argument for \p space.
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
218 * Then this function will allocate the space and enforce
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
219 * the #CX_BUFFER_FREE_CONTENTS flag.
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
220 *
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
221 * @param space pointer to the memory area, or \c NULL to allocate
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
222 * new memory
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
223 * @param capacity the capacity of the buffer
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
224 * @param allocator the allocator to use for allocating the structure and the automatic
989
8aa57a7fecc4 improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
225 * memory management within the buffer
8aa57a7fecc4 improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
226 * (if \c NULL, a default stdlib allocator will be used)
683
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
227 * @param flags buffer features (see cx_buffer_s.flags)
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
228 * @return a pointer to the buffer on success, \c NULL if a required allocation failed
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
229 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
230 cx_attr_malloc
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
231 cx_attr_dealloc(cxBufferFree, 1)
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
232 cx_attr_nodiscard
683
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
233 CxBuffer *cxBufferCreate(
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
234 void *space,
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
235 size_t capacity,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
236 const CxAllocator *allocator,
683
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
237 int flags
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
238 );
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
239
aa0d09f2d81c add convenience functions for allocating a buffer on the heap
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
240 /**
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 * Shifts the contents of the buffer by the given offset.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 * If the offset is positive, the contents are shifted to the right.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 * If auto extension is enabled, the buffer grows, if necessary.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 * In case the auto extension fails, this function returns a non-zero value and
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 * no contents are changed.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 * If auto extension is disabled, the contents that do not fit into the buffer
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 * are discarded.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 * If the offset is negative, the contents are shifted to the left where the
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 * first \p shift bytes are discarded.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 * The new size of the buffer is the old size minus the absolute shift value.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 * If this value is larger than the buffer size, the buffer is emptied (but
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 * not cleared, see the security note below).
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 * The buffer position gets shifted alongside with the content but is kept
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 * within the boundaries of the buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 * \note For situations where \c off_t is not large enough, there are specialized cxBufferShiftLeft() and
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 * cxBufferShiftRight() functions using a \c size_t as parameter type.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
262 * \attention
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
263 * Security Note: The shifting operation does \em not erase the previously occupied memory cells.
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
264 * But you can easily do that manually, e.g. by calling
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 * <code>memset(buffer->bytes, 0, shift)</code> for a right shift or
531
1b8624c8448e fix erroneous doc for cxBufferShift
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
266 * <code>memset(buffer->bytes + buffer->size, 0, buffer->capacity - buffer->size)</code>
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 * for a left shift.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
269 * @param buffer the buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
270 * @param shift the shift offset (negative means left shift)
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
271 * @return 0 on success, non-zero if a required auto-extension or copy-on-write fails
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
273 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 int cxBufferShift(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
275 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 off_t shift
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 * Shifts the buffer to the right.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 * See cxBufferShift() for details.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
283 * @param buffer the buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
284 * @param shift the shift offset
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
285 * @return 0 on success, non-zero if a required auto-extension or copy-on-write fails
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
286 * @see cxBufferShift()
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
288 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 int cxBufferShiftRight(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
290 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 size_t shift
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 * Shifts the buffer to the left.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 * See cxBufferShift() for details.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
298 * @param buffer the buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
299 * @param shift the positive shift offset
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
300 * @return usually zero, except the buffer uses copy-on-write and the allocation fails
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
301 * @see cxBufferShift()
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
303 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304 int cxBufferShiftLeft(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
305 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 size_t shift
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311 * Moves the position of the buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 * The new position is relative to the \p whence argument.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 * \li \c SEEK_SET marks the start of the buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 * \li \c SEEK_CUR marks the current position.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317 * \li \c SEEK_END marks the end of the buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 * With an offset of zero, this function sets the buffer position to zero
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 * (\c SEEK_SET), the buffer size (\c SEEK_END) or leaves the buffer position
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 * unchanged (\c SEEK_CUR).
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
323 * @param buffer the buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
324 * @param offset position offset relative to \p whence
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
325 * @param whence one of \c SEEK_SET, \c SEEK_CUR or \c SEEK_END
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
326 * @return 0 on success, non-zero if the position is invalid
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
329 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 int cxBufferSeek(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
331 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332 off_t offset,
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 int whence
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 * Clears the buffer by resetting the position and deleting the data.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 * The data is deleted by zeroing it with a call to memset().
761
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
340 * If you do not need that, you can use the faster cxBufferReset().
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 *
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
342 * \note If the #CX_BUFFER_COPY_ON_WRITE flag is set, this function
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
343 * will not erase the data and behave exactly as cxBufferReset().
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1016
diff changeset
344 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
345 * @param buffer the buffer to be cleared
761
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
346 * @see cxBufferReset()
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
348 cx_attr_nonnull
529
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
349 void cxBufferClear(CxBuffer *buffer);
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 /**
761
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
352 * Resets the buffer by resetting the position and size to zero.
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
353 *
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
354 * The data in the buffer is not deleted. If you need a safe
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
355 * reset of the buffer, use cxBufferClear().
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
356 *
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
357 * @param buffer the buffer to be cleared
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
358 * @see cxBufferClear()
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
359 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
360 cx_attr_nonnull
761
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
361 void cxBufferReset(CxBuffer *buffer);
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
362
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 759
diff changeset
363 /**
757
49ceea78fce7 fix incorrect documentation of cxBufferEof()
Mike Becker <universe@uap-core.de>
parents: 683
diff changeset
364 * Tests, if the buffer position has exceeded the buffer size.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
366 * @param buffer the buffer to test
1004
d8044fd5005c make cxBufferEof() return a bool
Mike Becker <universe@uap-core.de>
parents: 989
diff changeset
367 * @return true, if the current buffer position has exceeded the last
757
49ceea78fce7 fix incorrect documentation of cxBufferEof()
Mike Becker <universe@uap-core.de>
parents: 683
diff changeset
368 * byte of the buffer's contents.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
370 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
371 cx_attr_nodiscard
1004
d8044fd5005c make cxBufferEof() return a bool
Mike Becker <universe@uap-core.de>
parents: 989
diff changeset
372 bool cxBufferEof(const CxBuffer *buffer);
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 * Ensures that the buffer has a minimum capacity.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 * If the current capacity is not sufficient, the buffer will be extended.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
380 * @param buffer the buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
381 * @param capacity the minimum required capacity for this buffer
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
382 * @return 0 on success or a non-zero value on failure
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
384 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 int cxBufferMinimumCapacity(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
386 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 size_t capacity
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 * Writes data to a CxBuffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392 *
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
393 * If flushing is enabled and the buffer needs to flush, the data is flushed to
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
394 * the target until the target signals that it cannot take more data by
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
395 * returning zero via the respective write function. In that case, the remaining
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
396 * data in this buffer is shifted to the beginning of this buffer so that the
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
397 * newly available space can be used to append as much data as possible. This
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
398 * function only stops writing more elements, when the flush target and this
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
399 * buffer are both incapable of taking more data or all data has been written.
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
400 * The number returned by this function is the total number of elements that
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
401 * could be written during the process. It does not necessarily mean that those
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
402 * elements are still in this buffer, because some of them could have also be
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
403 * flushed already.
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
404 *
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
405 * If automatic flushing is not enabled, the position of the buffer is increased
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
406 * by the number of bytes written.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
407 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
408 * \note The signature is compatible with the fwrite() family of functions.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
409 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
410 * @param ptr a pointer to the memory area containing the bytes to be written
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
411 * @param size the length of one element
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
412 * @param nitems the element count
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
413 * @param buffer the CxBuffer to write to
537
16219eba3a0a fix doc error for cxBufferWrite
Mike Becker <universe@uap-core.de>
parents: 531
diff changeset
414 * @return the total count of elements written
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
415 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
416 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
417 size_t cxBufferWrite(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
418 const void *ptr,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
419 size_t size,
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
420 size_t nitems,
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
421 CxBuffer *buffer
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
422 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
423
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
424 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
425 * Reads data from a CxBuffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
426 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
427 * The position of the buffer is increased by the number of bytes read.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
428 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
429 * \note The signature is compatible with the fread() family of functions.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
430 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
431 * @param ptr a pointer to the memory area where to store the read data
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
432 * @param size the length of one element
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
433 * @param nitems the element count
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
434 * @param buffer the CxBuffer to read from
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
435 * @return the total number of elements read
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
436 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
437 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
438 size_t cxBufferRead(
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
439 void *ptr,
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
440 size_t size,
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
441 size_t nitems,
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
442 CxBuffer *buffer
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
443 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
444
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
445 /**
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
446 * Writes a character to a buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
447 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
448 * The least significant byte of the argument is written to the buffer. If the
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
449 * end of the buffer is reached and #CX_BUFFER_AUTO_EXTEND feature is enabled,
1005
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
450 * the buffer capacity is extended by cxBufferMinimumCapacity(). If the feature
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
451 * is disabled or buffer extension fails, \c EOF is returned.
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
452 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
453 * On successful write, the position of the buffer is increased.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
454 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
455 * @param buffer the buffer to write to
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
456 * @param c the character to write
1005
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
457 * @return the byte that has been written or \c EOF when the end of the stream is
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
458 * reached and automatic extension is not enabled or not possible
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
459 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
460 cx_attr_nonnull
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
461 int cxBufferPut(
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
462 CxBuffer *buffer,
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
463 int c
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
464 );
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
465
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
466 /**
1005
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
467 * Writes a terminating zero to a buffer.
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
468 *
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
469 * On successful write, \em neither the position \em nor the size of the buffer is
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
470 * increased.
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
471 *
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
472 * The purpose of this function is to have the written data ready to be used as
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
473 * a C string.
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
474 *
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
475 * @param buffer the buffer to write to
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
476 * @return zero, if the terminator could be written, non-zero otherwise
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
477 */
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
478 cx_attr_nonnull
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
479 int cxBufferTerminate(CxBuffer *buffer);
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
480
67fa386ce600 add cxBufferTerminate()
Mike Becker <universe@uap-core.de>
parents: 1004
diff changeset
481 /**
529
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
482 * Writes a string to a buffer.
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
483 *
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
484 * @param buffer the buffer
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
485 * @param str the zero-terminated string
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
486 * @return the number of bytes written
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
487 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
488 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
489 cx_attr_cstr_arg(2)
529
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
490 size_t cxBufferPutString(
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
491 CxBuffer *buffer,
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
492 const char *str
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
493 );
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
494
814d51173f20 #171 const qualifier and nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 501
diff changeset
495 /**
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
496 * Gets a character from a buffer.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
497 *
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
498 * The current position of the buffer is increased after a successful read.
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
499 *
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
500 * @param buffer the buffer to read from
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
501 * @return the character or \c EOF, if the end of the buffer is reached
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
502 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 948
diff changeset
503 cx_attr_nonnull
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
504 int cxBufferGet(CxBuffer *buffer);
483
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
505
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
506 #ifdef __cplusplus
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
507 }
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
508 #endif
929016224c3c add ported UCX buffer implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
509
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
510 #endif // UCX_BUFFER_H

mercurial