* @brief Deep-copy an existing queue. * * The returned queue owns its own backing vector and an independent * copy of every element. Element ordering is preserved. * * @param src Source queue to clone (must be non-NULL with a valid vector). * * @return Newly-allocated Queue with the same item size and contents, * or NULL on any failure (NULL src / OOM / vector op failure). */
| 119 | * |
| 120 | * Allocates a Queue header and an empty backing Vector. No elements |
| 121 | * are allocated until you push. |
| 122 | * |
| 123 | * @param itemSize Size in bytes of one element (must be > 0). |
| 124 | * |
| 125 | * @return Newly-allocated Queue the caller must free with |
| 126 | * @ref queue_deallocate, or NULL on: |
| 127 | * - `itemSize == 0` |
| 128 | * - Queue-header malloc failure |
| 129 | * - underlying vector_create failure |
| 130 | * |
| 131 | */ |
| 132 | Queue* queue_create(size_t itemSize) { |
| 133 | QUEUE_LOG("[queue_create]: enter itemSize=%zu", itemSize); |
| 134 | |
| 135 | if (itemSize == 0) { |
| 136 | QUEUE_LOG("[queue_create]: itemSize is zero -> NULL"); |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | Queue* q = (Queue*)malloc(sizeof(Queue)); |
| 141 | if (!q) { |
| 142 | QUEUE_LOG("[queue_create]: malloc(sizeof(Queue)) failed -> NULL"); |
| 143 | return NULL; |
| 144 | } |
| 145 | |
| 146 | q->vec = vector_create(itemSize); |
| 147 | if (!q->vec) { |
| 148 | QUEUE_LOG("[queue_create]: vector_create(%zu) failed -> NULL", itemSize); |
| 149 | free(q); |
| 150 | return NULL; |
| 151 | } |
| 152 | q->frontIndex = 0; |
| 153 | QUEUE_LOG("[queue_create]: exit ok q=%p vec=%p", (void*)q, (void*)q->vec); |
| 154 | return q; |
nothing calls this directly
no test coverage detected