1.1 --- a/src/cx/buffer.h Mon Apr 18 17:26:21 2022 +0200 1.2 +++ b/src/cx/buffer.h Sun Apr 24 14:54:50 2022 +0200 1.3 @@ -84,7 +84,7 @@ 1.4 unsigned char *bytes; 1.5 }; 1.6 /** The allocator to use for automatic memory management. */ 1.7 - CxAllocator *allocator; 1.8 + CxAllocator const *allocator; 1.9 /** Current position of the buffer. */ 1.10 size_t pos; 1.11 /** Current capacity (i.e. maximum size) of the buffer. */ 1.12 @@ -120,11 +120,12 @@ 1.13 * @param flags buffer features (see cx_buffer_s.flags) 1.14 * @return zero on success, non-zero if a required allocation failed 1.15 */ 1.16 +__attribute__((__nonnull__(1, 4))) 1.17 int cxBufferInit( 1.18 CxBuffer *buffer, 1.19 void *space, 1.20 size_t capacity, 1.21 - CxAllocator *allocator, 1.22 + CxAllocator const *allocator, 1.23 int flags 1.24 ); 1.25 1.26 @@ -135,37 +136,10 @@ 1.27 * 1.28 * @param buffer the buffer which contents shall be destroyed 1.29 */ 1.30 +__attribute__((__nonnull__)) 1.31 void cxBufferDestroy(CxBuffer *buffer); 1.32 1.33 /** 1.34 - * Creates a new buffer and fills it with content copied from another buffer. 1.35 - * 1.36 - * \note The #CX_BUFFER_FREE_CONTENTS feature is enforced for the new buffer. 1.37 - * 1.38 - * @param src the source buffer 1.39 - * @param start the start position of extraction 1.40 - * @param length the count of bytes to extract (must not be zero) 1.41 - * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled) 1.42 - * @return a new buffer containing the extraction 1.43 - */ 1.44 -CxBuffer *cxBufferExtract( 1.45 - CxBuffer *src, 1.46 - size_t start, 1.47 - size_t length, 1.48 - int flags 1.49 -); 1.50 - 1.51 -/** 1.52 - * A shorthand macro for copying an entire buffer. 1.53 - * 1.54 - * @param src the source buffer 1.55 - * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled) 1.56 - * @return a new buffer with the copied content 1.57 - */ 1.58 -#define cxBufferClone(src, flags) cxBufferExtract(src, 0, (src)->capacity, flags) 1.59 - 1.60 - 1.61 -/** 1.62 * Shifts the contents of the buffer by the given offset. 1.63 * 1.64 * If the offset is positive, the contents are shifted to the right. 1.65 @@ -198,6 +172,7 @@ 1.66 * @param shift the shift offset (negative means left shift) 1.67 * @return 0 on success, non-zero if a required auto-extension fails 1.68 */ 1.69 +__attribute__((__nonnull__)) 1.70 int cxBufferShift( 1.71 CxBuffer *buffer, 1.72 off_t shift 1.73 @@ -212,6 +187,7 @@ 1.74 * @return 0 on success, non-zero if a required auto-extension fails 1.75 * @see cxBufferShift() 1.76 */ 1.77 +__attribute__((__nonnull__)) 1.78 int cxBufferShiftRight( 1.79 CxBuffer *buffer, 1.80 size_t shift 1.81 @@ -229,6 +205,7 @@ 1.82 * @return always zero 1.83 * @see cxBufferShift() 1.84 */ 1.85 +__attribute__((__nonnull__)) 1.86 int cxBufferShiftLeft( 1.87 CxBuffer *buffer, 1.88 size_t shift 1.89 @@ -254,6 +231,7 @@ 1.90 * @return 0 on success, non-zero if the position is invalid 1.91 * 1.92 */ 1.93 +__attribute__((__nonnull__)) 1.94 int cxBufferSeek( 1.95 CxBuffer *buffer, 1.96 off_t offset, 1.97 @@ -267,8 +245,8 @@ 1.98 * 1.99 * @param buffer the buffer to be cleared 1.100 */ 1.101 -#define cxBufferClear(buffer) memset((buffer)->bytes, 0, (buffer)->size); \ 1.102 - (buffer)->size = 0; (buffer)->pos = 0; 1.103 +__attribute__((__nonnull__)) 1.104 +void cxBufferClear(CxBuffer *buffer); 1.105 1.106 /** 1.107 * Tests, if the buffer position has exceeded the buffer capacity. 1.108 @@ -277,7 +255,8 @@ 1.109 * @return non-zero, if the current buffer position has exceeded the last 1.110 * available byte of the buffer. 1.111 */ 1.112 -int cxBufferEof(CxBuffer *buffer); 1.113 +__attribute__((__nonnull__)) 1.114 +int cxBufferEof(CxBuffer const *buffer); 1.115 1.116 1.117 /** 1.118 @@ -289,6 +268,7 @@ 1.119 * @param capacity the minimum required capacity for this buffer 1.120 * @return 0 on success or a non-zero value on failure 1.121 */ 1.122 +__attribute__((__nonnull__)) 1.123 int cxBufferMinimumCapacity( 1.124 CxBuffer *buffer, 1.125 size_t capacity 1.126 @@ -307,6 +287,7 @@ 1.127 * @param buffer the CxBuffer to write to 1.128 * @return the total count of bytes written 1.129 */ 1.130 +__attribute__((__nonnull__)) 1.131 size_t cxBufferWrite( 1.132 void const *ptr, 1.133 size_t size, 1.134 @@ -327,6 +308,7 @@ 1.135 * @param buffer the CxBuffer to read from 1.136 * @return the total number of elements read 1.137 */ 1.138 +__attribute__((__nonnull__)) 1.139 size_t cxBufferRead( 1.140 void *ptr, 1.141 size_t size, 1.142 @@ -349,12 +331,26 @@ 1.143 * @return the byte that has bean written or \c EOF when the end of the stream is 1.144 * reached and automatic extension is not enabled or not possible 1.145 */ 1.146 +__attribute__((__nonnull__)) 1.147 int cxBufferPut( 1.148 CxBuffer *buffer, 1.149 int c 1.150 ); 1.151 1.152 /** 1.153 + * Writes a string to a buffer. 1.154 + * 1.155 + * @param buffer the buffer 1.156 + * @param str the zero-terminated string 1.157 + * @return the number of bytes written 1.158 + */ 1.159 +__attribute__((__nonnull__)) 1.160 +size_t cxBufferPutString( 1.161 + CxBuffer *buffer, 1.162 + const char *str 1.163 +); 1.164 + 1.165 +/** 1.166 * Gets a character from a buffer. 1.167 * 1.168 * The current position of the buffer is increased after a successful read. 1.169 @@ -362,20 +358,9 @@ 1.170 * @param buffer the buffer to read from 1.171 * @return the character or \c EOF, if the end of the buffer is reached 1.172 */ 1.173 +__attribute__((__nonnull__)) 1.174 int cxBufferGet(CxBuffer *buffer); 1.175 1.176 -/** 1.177 - * Writes a string to a buffer. 1.178 - * 1.179 - * @param buffer the buffer 1.180 - * @param str the zero-terminated string 1.181 - * @return the number of bytes written 1.182 - */ 1.183 -size_t cxBufferPutString( 1.184 - CxBuffer *buffer, 1.185 - const char *str 1.186 -); 1.187 - 1.188 #ifdef __cplusplus 1.189 } 1.190 #endif