src/cx/buffer.h

changeset 1675
36c0fb2b60b2
parent 1654
5ab3fe0b7859
--- a/src/cx/buffer.h	Sun Dec 28 15:45:39 2025 +0100
+++ b/src/cx/buffer.h	Sun Dec 28 17:31:20 2025 +0100
@@ -50,10 +50,6 @@
 #include "allocator.h"
 #include "string.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /**
  * No buffer features enabled (all flags cleared).
  */
@@ -177,8 +173,8 @@
  * @param flags buffer features (see cx_buffer_s.flags)
  * @return zero on success, non-zero if a required allocation failed
  */
-cx_attr_nonnull_arg(1)
-CX_EXPORT int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator,
+CX_EXTERN CX_NONNULL_ARG(1)
+int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator,
         void *space, size_t capacity, int flags);
 
 /**
@@ -190,8 +186,8 @@
  * @param buffer the buffer which contents shall be destroyed
  * @see cxBufferInit()
  */
-cx_attr_nonnull
-CX_EXPORT void cxBufferDestroy(CxBuffer *buffer);
+CX_EXTERN CX_NONNULL
+void cxBufferDestroy(CxBuffer *buffer);
 
 /**
  * Deallocates the buffer.
@@ -202,7 +198,8 @@
  * @param buffer the buffer to deallocate
  * @see cxBufferCreate()
  */
-CX_EXPORT void cxBufferFree(CxBuffer *buffer);
+CX_EXTERN
+void cxBufferFree(CxBuffer *buffer);
 
 /**
  * Allocates and initializes a fresh buffer.
@@ -228,8 +225,8 @@
  * @param flags buffer features (see cx_buffer_s.flags)
  * @return a pointer to the buffer on success, @c NULL if a required allocation failed
  */
-cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard
-CX_EXPORT CxBuffer *cxBufferCreate(const CxAllocator *allocator, void *space,
+CX_EXTERN CX_MALLOC CX_DEALLOC(cxBufferFree, 1) CX_NODISCARD
+CxBuffer *cxBufferCreate(const CxAllocator *allocator, void *space,
                                    size_t capacity, int flags);
 
 /**
@@ -268,8 +265,8 @@
  * @see cxBufferShiftLeft()
  * @see cxBufferShiftRight()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferShift(CxBuffer *buffer, off_t shift);
+CX_EXTERN CX_NONNULL
+int cxBufferShift(CxBuffer *buffer, off_t shift);
 
 /**
  * Shifts the buffer to the right.
@@ -281,8 +278,8 @@
  * @retval non-zero if a required auto-extension or copy-on-write fails
  * @see cxBufferShift()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferShiftRight(CxBuffer *buffer, size_t shift);
+CX_EXTERN CX_NONNULL
+int cxBufferShiftRight(CxBuffer *buffer, size_t shift);
 
 /**
  * Shifts the buffer to the left.
@@ -294,8 +291,8 @@
  * @retval non-zero if the buffer uses copy-on-write and the allocation fails
  * @see cxBufferShift()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferShiftLeft(CxBuffer *buffer, size_t shift);
+CX_EXTERN CX_NONNULL
+int cxBufferShiftLeft(CxBuffer *buffer, size_t shift);
 
 
 /**
@@ -318,8 +315,8 @@
  * @retval non-zero if the position is invalid
  *
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence);
+CX_EXTERN CX_NONNULL
+int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence);
 
 /**
  * Discards items from the end of the buffer.
@@ -332,8 +329,8 @@
  * @param nitems the number of items to discard
  * @return the actual number of discarded items
  */
-cx_attr_nonnull
-CX_EXPORT size_t cxBufferPop(CxBuffer *buffer, size_t size, size_t nitems);
+CX_EXTERN CX_NONNULL
+size_t cxBufferPop(CxBuffer *buffer, size_t size, size_t nitems);
 
 /**
  * Clears the buffer by resetting the position and deleting the data.
@@ -347,8 +344,8 @@
  * @param buffer the buffer to be cleared
  * @see cxBufferReset()
  */
-cx_attr_nonnull
-CX_EXPORT void cxBufferClear(CxBuffer *buffer);
+CX_EXTERN CX_NONNULL
+void cxBufferClear(CxBuffer *buffer);
 
 /**
  * Resets the buffer by resetting the position and size to zero.
@@ -359,8 +356,8 @@
  * @param buffer the buffer to be cleared
  * @see cxBufferClear()
  */
-cx_attr_nonnull
-CX_EXPORT void cxBufferReset(CxBuffer *buffer);
+CX_EXTERN CX_NONNULL
+void cxBufferReset(CxBuffer *buffer);
 
 /**
  * Tests, if the buffer position has exceeded the buffer size.
@@ -370,8 +367,8 @@
  * byte of the buffer's contents
  * @retval false otherwise
  */
-cx_attr_nonnull cx_attr_nodiscard
-CX_EXPORT bool cxBufferEof(const CxBuffer *buffer);
+CX_EXTERN CX_NONNULL CX_NODISCARD
+bool cxBufferEof(const CxBuffer *buffer);
 
 /**
  * Ensures that the buffer has the required capacity.
@@ -391,8 +388,8 @@
  * @see cxBufferShrink()
  * @see cxBufferMinimumCapacity()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferReserve(CxBuffer *buffer, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cxBufferReserve(CxBuffer *buffer, size_t capacity);
 
 /**
  * Limits the buffer's capacity.
@@ -410,8 +407,8 @@
  * @see cxBufferReserve()
  * @see cxBufferMinimumCapacity()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferMaximumCapacity(CxBuffer *buffer, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cxBufferMaximumCapacity(CxBuffer *buffer, size_t capacity);
 
 /**
  * Ensures that the buffer has a minimum capacity.
@@ -430,8 +427,8 @@
  * @see cxBufferReserve()
  * @see cxBufferShrink()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity);
 
 /**
  * Shrinks the capacity of the buffer to fit its current size.
@@ -450,8 +447,8 @@
  * @see cxBufferReserve()
  * @see cxBufferMinimumCapacity()
  */
-cx_attr_nonnull
-CX_EXPORT void cxBufferShrink(CxBuffer *buffer, size_t reserve);
+CX_EXTERN CX_NONNULL
+void cxBufferShrink(CxBuffer *buffer, size_t reserve);
 
 /**
  * Writes data to a CxBuffer.
@@ -474,8 +471,8 @@
  * @see cxBufferAppend()
  * @see cxBufferRead()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cxBufferWrite(const void *ptr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cxBufferWrite(const void *ptr, size_t size,
         size_t nitems, CxBuffer *buffer);
 
 /**
@@ -497,8 +494,8 @@
  * @see cxBufferWrite()
  * @see cxBufferRead()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cxBufferAppend(const void *ptr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cxBufferAppend(const void *ptr, size_t size,
         size_t nitems, CxBuffer *buffer);
 
 /**
@@ -516,8 +513,8 @@
  * @see cxBufferWrite()
  * @see cxBufferAppend()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cxBufferRead(void *ptr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cxBufferRead(void *ptr, size_t size,
         size_t nitems, CxBuffer *buffer);
 
 /**
@@ -540,8 +537,8 @@
  * stream is reached, and automatic extension is not enabled or not possible
  * @see cxBufferTerminate()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferPut(CxBuffer *buffer, int c);
+CX_EXTERN CX_NONNULL
+int cxBufferPut(CxBuffer *buffer, int c);
 
 /**
  * Writes a terminating zero to a buffer at the current position.
@@ -555,8 +552,8 @@
  * @return zero, if the terminator could be written, non-zero otherwise
  * @see cxBufferShrink()
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferTerminate(CxBuffer *buffer);
+CX_EXTERN CX_NONNULL
+int cxBufferTerminate(CxBuffer *buffer);
 
 /**
  * Internal function - do not use.
@@ -566,8 +563,8 @@
  * @return the number of bytes written
  * @see cxBufferPutString()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_buffer_put_string(CxBuffer *buffer, cxstring str);
+CX_EXTERN CX_NONNULL
+size_t cx_buffer_put_string(CxBuffer *buffer, cxstring str);
 
 /**
  * Writes a string to a buffer with cxBufferWrite().
@@ -588,8 +585,8 @@
  * @return the number of bytes written
  * @see cxBufferPutString()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_buffer_append_string(CxBuffer *buffer, cxstring str);
+CX_EXTERN CX_NONNULL
+size_t cx_buffer_append_string(CxBuffer *buffer, cxstring str);
 
 /**
  * Appends a string to a buffer with cxBufferAppend().
@@ -610,8 +607,8 @@
  * @param buffer the buffer to read from
  * @return the character or @c EOF, if the end of the buffer is reached
  */
-cx_attr_nonnull
-CX_EXPORT int cxBufferGet(CxBuffer *buffer);
+CX_EXTERN CX_NONNULL
+int cxBufferGet(CxBuffer *buffer);
 
 /**
  * Gets the data in a buffer as a @c cxstring.
@@ -619,7 +616,8 @@
  * @param buffer the buffer
  * @return the data in the buffer interpreted as a @c cxstring
  */
-CX_INLINE cxstring cx_bstr(CxBuffer *buffer) {
+CX_NONNULL CX_INLINE
+cxstring cx_bstr(CxBuffer *buffer) {
     return cx_strn(buffer->space, buffer->size);
 }
 
@@ -629,12 +627,9 @@
  * @param buffer the buffer
  * @return the data in the buffer interpreted as a @c cxmutstr
  */
-CX_INLINE cxmutstr cx_bstr_m(CxBuffer *buffer) {
+CX_NONNULL CX_INLINE
+cxmutstr cx_bstr_m(CxBuffer *buffer) {
     return cx_mutstrn(buffer->space, buffer->size);
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif // UCX_BUFFER_H

mercurial