Thu, 23 Feb 2023 22:27:41 +0100
add CX_LINKED_LIST_SORT_SBO_SIZE macro
universe@599 | 1 | /* |
universe@599 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
universe@599 | 3 | * |
universe@599 | 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
universe@599 | 5 | * |
universe@599 | 6 | * Redistribution and use in source and binary forms, with or without |
universe@599 | 7 | * modification, are permitted provided that the following conditions are met: |
universe@599 | 8 | * |
universe@599 | 9 | * 1. Redistributions of source code must retain the above copyright |
universe@599 | 10 | * notice, this list of conditions and the following disclaimer. |
universe@599 | 11 | * |
universe@599 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@599 | 13 | * notice, this list of conditions and the following disclaimer in the |
universe@599 | 14 | * documentation and/or other materials provided with the distribution. |
universe@599 | 15 | * |
universe@599 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@599 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@599 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
universe@599 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
universe@599 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
universe@599 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
universe@599 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
universe@599 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
universe@599 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
universe@599 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
universe@599 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
universe@599 | 27 | */ |
universe@599 | 28 | /** |
universe@599 | 29 | * \file printf.h |
universe@599 | 30 | * \brief Wrapper for write functions with a printf-like interface. |
universe@599 | 31 | * \author Mike Becker |
universe@599 | 32 | * \author Olaf Wintermann |
universe@599 | 33 | * \version 3.0 |
universe@599 | 34 | * \copyright 2-Clause BSD License |
universe@599 | 35 | */ |
universe@599 | 36 | |
universe@599 | 37 | #ifndef UCX_PRINTF_H |
universe@599 | 38 | #define UCX_PRINTF_H |
universe@599 | 39 | |
universe@599 | 40 | #include "common.h" |
universe@599 | 41 | #include "string.h" |
universe@599 | 42 | #include <stdarg.h> |
universe@599 | 43 | |
universe@599 | 44 | #ifdef __cplusplus |
universe@599 | 45 | extern "C" { |
universe@599 | 46 | #endif |
universe@599 | 47 | |
universe@599 | 48 | /** |
universe@599 | 49 | * A \c fprintf like function which writes the output to a stream by |
universe@599 | 50 | * using a write_func. |
universe@599 | 51 | * |
universe@599 | 52 | * @param stream the stream the data is written to |
universe@599 | 53 | * @param wfc the write function |
universe@599 | 54 | * @param fmt format string |
universe@599 | 55 | * @param ... additional arguments |
universe@599 | 56 | * @return the total number of bytes written |
universe@599 | 57 | */ |
universe@635 | 58 | __attribute__((__nonnull__(1, 2, 3), __format__(printf, 3, 4))) |
universe@635 | 59 | int cx_fprintf( |
universe@635 | 60 | void *stream, |
universe@635 | 61 | cx_write_func wfc, |
universe@635 | 62 | char const *fmt, |
universe@635 | 63 | ... |
universe@635 | 64 | ); |
universe@599 | 65 | |
universe@599 | 66 | /** |
universe@599 | 67 | * A \c vfprintf like function which writes the output to a stream by |
universe@599 | 68 | * using a write_func. |
universe@599 | 69 | * |
universe@599 | 70 | * @param stream the stream the data is written to |
universe@599 | 71 | * @param wfc the write function |
universe@599 | 72 | * @param fmt format string |
universe@599 | 73 | * @param ap argument list |
universe@599 | 74 | * @return the total number of bytes written |
universe@599 | 75 | * @see cx_fprintf() |
universe@599 | 76 | */ |
universe@635 | 77 | __attribute__((__nonnull__)) |
universe@635 | 78 | int cx_vfprintf( |
universe@635 | 79 | void *stream, |
universe@635 | 80 | cx_write_func wfc, |
universe@635 | 81 | char const *fmt, |
universe@635 | 82 | va_list ap |
universe@635 | 83 | ); |
universe@599 | 84 | |
universe@599 | 85 | /** |
universe@599 | 86 | * A \c asprintf like function which allocates space for a string |
universe@599 | 87 | * the result is written to. |
universe@599 | 88 | * |
universe@599 | 89 | * \note The resulting string is guaranteed to be zero-terminated. |
universe@599 | 90 | * |
universe@599 | 91 | * @param allocator the CxAllocator used for allocating the string |
universe@599 | 92 | * @param fmt format string |
universe@599 | 93 | * @param ... additional arguments |
universe@599 | 94 | * @return the formatted string |
universe@599 | 95 | * @see cx_strfree_a() |
universe@599 | 96 | */ |
universe@635 | 97 | __attribute__((__nonnull__(1, 2), __format__(printf, 2, 3))) |
universe@635 | 98 | cxmutstr cx_asprintf_a( |
universe@635 | 99 | CxAllocator *allocator, |
universe@635 | 100 | char const *fmt, |
universe@635 | 101 | ... |
universe@635 | 102 | ); |
universe@599 | 103 | |
universe@599 | 104 | /** |
universe@599 | 105 | * A \c asprintf like function which allocates space for a string |
universe@599 | 106 | * the result is written to. |
universe@599 | 107 | * |
universe@599 | 108 | * \note The resulting string is guaranteed to be zero-terminated. |
universe@599 | 109 | * |
universe@599 | 110 | * @param fmt format string |
universe@599 | 111 | * @param ... additional arguments |
universe@599 | 112 | * @return the formatted string |
universe@599 | 113 | * @see cx_strfree() |
universe@599 | 114 | */ |
universe@599 | 115 | #define cx_asprintf(fmt, ...) \ |
universe@599 | 116 | cx_asprintf_a(cxDefaultAllocator, fmt, __VA_ARGS__) |
universe@599 | 117 | |
universe@599 | 118 | /** |
universe@599 | 119 | * A \c vasprintf like function which allocates space for a string |
universe@599 | 120 | * the result is written to. |
universe@599 | 121 | * |
universe@599 | 122 | * \note The resulting string is guaranteed to be zero-terminated. |
universe@599 | 123 | * |
universe@599 | 124 | * @param allocator the CxAllocator used for allocating the string |
universe@599 | 125 | * @param fmt format string |
universe@599 | 126 | * @param ap argument list |
universe@599 | 127 | * @return the formatted string |
universe@599 | 128 | * @see cx_asprintf_a() |
universe@599 | 129 | */ |
universe@635 | 130 | __attribute__((__nonnull__)) |
universe@635 | 131 | cxmutstr cx_vasprintf_a( |
universe@635 | 132 | CxAllocator *allocator, |
universe@635 | 133 | char const *fmt, |
universe@635 | 134 | va_list ap |
universe@635 | 135 | ); |
universe@599 | 136 | |
universe@599 | 137 | /** |
universe@599 | 138 | * A \c vasprintf like function which allocates space for a string |
universe@599 | 139 | * the result is written to. |
universe@599 | 140 | * |
universe@599 | 141 | * \note The resulting string is guaranteed to be zero-terminated. |
universe@599 | 142 | * |
universe@599 | 143 | * @param fmt format string |
universe@599 | 144 | * @param ap argument list |
universe@599 | 145 | * @return the formatted string |
universe@599 | 146 | * @see cx_asprintf() |
universe@599 | 147 | */ |
universe@599 | 148 | #define cx_vasprintf(fmt, ap) cx_vasprintf_a(cxDefaultAllocator, fmt, ap) |
universe@599 | 149 | |
universe@599 | 150 | /** |
universe@599 | 151 | * A \c printf like function which writes the output to a CxBuffer. |
universe@599 | 152 | * |
universe@635 | 153 | * @param buffer a pointer to the buffer the data is written to |
universe@599 | 154 | * @param fmt the format string |
universe@599 | 155 | * @param ... additional arguments |
universe@599 | 156 | * @return the total number of bytes written |
universe@599 | 157 | * @see ucx_fprintf() |
universe@599 | 158 | */ |
universe@599 | 159 | #define cx_bprintf(buffer, fmt, ...) cx_fprintf((CxBuffer*)buffer, \ |
universe@599 | 160 | (cx_write_func) cxBufferWrite, fmt, __VA_ARGS__) |
universe@599 | 161 | |
universe@599 | 162 | #ifdef __cplusplus |
universe@599 | 163 | } // extern "C" |
universe@599 | 164 | #endif |
universe@599 | 165 | |
universe@599 | 166 | #endif //UCX_PRINTF_H |