/** @license 2023 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). Temporary strings duplicated from substrings. @std C89 */ #include "lorem.h" #include #include /*#define ARRAY_NAME block #define ARRAY_TYPE char * #include "array.h"*/ #define POOL_NAME char #define POOL_TYPE char #include "pool.h" static struct char_pool pool; const char *lorem_dup(const struct substring sub) { char *string; if(!sub.sub) { errno = EDOM; return 0; } if(sub.size == ~(size_t)0) { errno = ERANGE; return 0; } if(!char_pool_buffer(&pool, sub.size + 1)) return 0; assert(pool.capacity0 - pool.slots.data[0].size >= sub.size + 1); string = pool.slots.data[0].slab + pool.slots.data[0].size; memcpy(string, sub.sub, sub.size); string[sub.size] = '\0'; pool.slots.data[0].size += sub.size + 1; return string; } void lorem_(void) { char_pool_(&pool); }