-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorRestOutHeader.c
More file actions
46 lines (38 loc) · 1.53 KB
/
Copy pathcorRestOutHeader.c
File metadata and controls
46 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// FILE corRestOutHeader.c
//
// AUTHOR Ken Zangelin
//
// Copyright 2026 Seamware
// SPDX-License-Identifier: Apache-2.0
//
#include <stdbool.h> // bool
#include <string.h> // memcpy
#include "kalloc/kaAlloc.h" // kaAlloc
#include "corRest/CorRestIn.h" // COR_REST_KV_GROW_SIZE
#include "corRest/CorRestState.h" // corRest
#include "corRest/corRestOutHeader.h" // Own interface
// -----------------------------------------------------------------------------
//
// corRestOutHeaderAdd -
//
bool corRestOutHeaderAdd(const char* key, const char* value)
{
// Grow the array if the inline (or last-grown) capacity is exhausted.
// Mirrors the in-side resize in corRestInit.c — same allocator, same
// growth step.
if (corRest.out.headerCount >= corRest.out.headerSize)
{
int newSize = corRest.out.headerSize + COR_REST_KV_GROW_SIZE;
CorRestKeyValue* newV = (CorRestKeyValue*) kaAlloc(&corRest.kalloc, newSize * sizeof(CorRestKeyValue));
if (newV == NULL)
return false;
memcpy(newV, corRest.out.headerV, corRest.out.headerCount * sizeof(CorRestKeyValue));
corRest.out.headerV = newV;
corRest.out.headerSize = newSize;
}
corRest.out.headerV[corRest.out.headerCount].key = (char*) key;
corRest.out.headerV[corRest.out.headerCount].value = (char*) value;
corRest.out.headerCount++;
return true;
}