util/sha1: rework _mesa_sha1_{init,final}
[mesa.git] / src / util / ralloc.c
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdint.h>
30
31 /* Android defines SIZE_MAX in limits.h, instead of the standard stdint.h */
32 #ifdef ANDROID
33 #include <limits.h>
34 #endif
35
36 /* Some versions of MinGW are missing _vscprintf's declaration, although they
37 * still provide the symbol in the import library. */
38 #ifdef __MINGW32__
39 _CRTIMP int _vscprintf(const char *format, va_list argptr);
40 #endif
41
42 #include "ralloc.h"
43
44 #ifndef va_copy
45 #ifdef __va_copy
46 #define va_copy(dest, src) __va_copy((dest), (src))
47 #else
48 #define va_copy(dest, src) (dest) = (src)
49 #endif
50 #endif
51
52 #define CANARY 0x5A1106
53
54 /* Align the header's size so that ralloc() allocations will return with the
55 * same alignment as a libc malloc would have (8 on 32-bit GLIBC, 16 on
56 * 64-bit), avoiding performance penalities on x86 and alignment faults on
57 * ARM.
58 */
59 struct
60 #ifdef _MSC_VER
61 __declspec(align(8))
62 #elif defined(__LP64__)
63 __attribute__((aligned(16)))
64 #else
65 __attribute__((aligned(8)))
66 #endif
67 ralloc_header
68 {
69 #ifdef DEBUG
70 /* A canary value used to determine whether a pointer is ralloc'd. */
71 unsigned canary;
72 #endif
73
74 struct ralloc_header *parent;
75
76 /* The first child (head of a linked list) */
77 struct ralloc_header *child;
78
79 /* Linked list of siblings */
80 struct ralloc_header *prev;
81 struct ralloc_header *next;
82
83 void (*destructor)(void *);
84 };
85
86 typedef struct ralloc_header ralloc_header;
87
88 static void unlink_block(ralloc_header *info);
89 static void unsafe_free(ralloc_header *info);
90
91 static ralloc_header *
92 get_header(const void *ptr)
93 {
94 ralloc_header *info = (ralloc_header *) (((char *) ptr) -
95 sizeof(ralloc_header));
96 #ifdef DEBUG
97 assert(info->canary == CANARY);
98 #endif
99 return info;
100 }
101
102 #define PTR_FROM_HEADER(info) (((char *) info) + sizeof(ralloc_header))
103
104 static void
105 add_child(ralloc_header *parent, ralloc_header *info)
106 {
107 if (parent != NULL) {
108 info->parent = parent;
109 info->next = parent->child;
110 parent->child = info;
111
112 if (info->next != NULL)
113 info->next->prev = info;
114 }
115 }
116
117 void *
118 ralloc_context(const void *ctx)
119 {
120 return ralloc_size(ctx, 0);
121 }
122
123 void *
124 ralloc_size(const void *ctx, size_t size)
125 {
126 void *block = malloc(size + sizeof(ralloc_header));
127 ralloc_header *info;
128 ralloc_header *parent;
129
130 if (unlikely(block == NULL))
131 return NULL;
132
133 info = (ralloc_header *) block;
134 /* measurements have shown that calloc is slower (because of
135 * the multiplication overflow checking?), so clear things
136 * manually
137 */
138 info->parent = NULL;
139 info->child = NULL;
140 info->prev = NULL;
141 info->next = NULL;
142 info->destructor = NULL;
143
144 parent = ctx != NULL ? get_header(ctx) : NULL;
145
146 add_child(parent, info);
147
148 #ifdef DEBUG
149 info->canary = CANARY;
150 #endif
151
152 return PTR_FROM_HEADER(info);
153 }
154
155 void *
156 rzalloc_size(const void *ctx, size_t size)
157 {
158 void *ptr = ralloc_size(ctx, size);
159
160 if (likely(ptr))
161 memset(ptr, 0, size);
162
163 return ptr;
164 }
165
166 /* helper function - assumes ptr != NULL */
167 static void *
168 resize(void *ptr, size_t size)
169 {
170 ralloc_header *child, *old, *info;
171
172 old = get_header(ptr);
173 info = realloc(old, size + sizeof(ralloc_header));
174
175 if (info == NULL)
176 return NULL;
177
178 /* Update parent and sibling's links to the reallocated node. */
179 if (info != old && info->parent != NULL) {
180 if (info->parent->child == old)
181 info->parent->child = info;
182
183 if (info->prev != NULL)
184 info->prev->next = info;
185
186 if (info->next != NULL)
187 info->next->prev = info;
188 }
189
190 /* Update child->parent links for all children */
191 for (child = info->child; child != NULL; child = child->next)
192 child->parent = info;
193
194 return PTR_FROM_HEADER(info);
195 }
196
197 void *
198 reralloc_size(const void *ctx, void *ptr, size_t size)
199 {
200 if (unlikely(ptr == NULL))
201 return ralloc_size(ctx, size);
202
203 assert(ralloc_parent(ptr) == ctx);
204 return resize(ptr, size);
205 }
206
207 void *
208 ralloc_array_size(const void *ctx, size_t size, unsigned count)
209 {
210 if (count > SIZE_MAX/size)
211 return NULL;
212
213 return ralloc_size(ctx, size * count);
214 }
215
216 void *
217 rzalloc_array_size(const void *ctx, size_t size, unsigned count)
218 {
219 if (count > SIZE_MAX/size)
220 return NULL;
221
222 return rzalloc_size(ctx, size * count);
223 }
224
225 void *
226 reralloc_array_size(const void *ctx, void *ptr, size_t size, unsigned count)
227 {
228 if (count > SIZE_MAX/size)
229 return NULL;
230
231 return reralloc_size(ctx, ptr, size * count);
232 }
233
234 void
235 ralloc_free(void *ptr)
236 {
237 ralloc_header *info;
238
239 if (ptr == NULL)
240 return;
241
242 info = get_header(ptr);
243 unlink_block(info);
244 unsafe_free(info);
245 }
246
247 static void
248 unlink_block(ralloc_header *info)
249 {
250 /* Unlink from parent & siblings */
251 if (info->parent != NULL) {
252 if (info->parent->child == info)
253 info->parent->child = info->next;
254
255 if (info->prev != NULL)
256 info->prev->next = info->next;
257
258 if (info->next != NULL)
259 info->next->prev = info->prev;
260 }
261 info->parent = NULL;
262 info->prev = NULL;
263 info->next = NULL;
264 }
265
266 static void
267 unsafe_free(ralloc_header *info)
268 {
269 /* Recursively free any children...don't waste time unlinking them. */
270 ralloc_header *temp;
271 while (info->child != NULL) {
272 temp = info->child;
273 info->child = temp->next;
274 unsafe_free(temp);
275 }
276
277 /* Free the block itself. Call the destructor first, if any. */
278 if (info->destructor != NULL)
279 info->destructor(PTR_FROM_HEADER(info));
280
281 free(info);
282 }
283
284 void
285 ralloc_steal(const void *new_ctx, void *ptr)
286 {
287 ralloc_header *info, *parent;
288
289 if (unlikely(ptr == NULL))
290 return;
291
292 info = get_header(ptr);
293 parent = get_header(new_ctx);
294
295 unlink_block(info);
296
297 add_child(parent, info);
298 }
299
300 void
301 ralloc_adopt(const void *new_ctx, void *old_ctx)
302 {
303 ralloc_header *new_info, *old_info, *child;
304
305 if (unlikely(old_ctx == NULL))
306 return;
307
308 old_info = get_header(old_ctx);
309 new_info = get_header(new_ctx);
310
311 /* If there are no children, bail. */
312 if (unlikely(old_info->child == NULL))
313 return;
314
315 /* Set all the children's parent to new_ctx; get a pointer to the last child. */
316 for (child = old_info->child; child->next != NULL; child = child->next) {
317 child->parent = new_info;
318 }
319
320 /* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */
321 child->next = new_info->child;
322 child->parent = new_info;
323 new_info->child = old_info->child;
324 old_info->child = NULL;
325 }
326
327 void *
328 ralloc_parent(const void *ptr)
329 {
330 ralloc_header *info;
331
332 if (unlikely(ptr == NULL))
333 return NULL;
334
335 info = get_header(ptr);
336 return info->parent ? PTR_FROM_HEADER(info->parent) : NULL;
337 }
338
339 void
340 ralloc_set_destructor(const void *ptr, void(*destructor)(void *))
341 {
342 ralloc_header *info = get_header(ptr);
343 info->destructor = destructor;
344 }
345
346 char *
347 ralloc_strdup(const void *ctx, const char *str)
348 {
349 size_t n;
350 char *ptr;
351
352 if (unlikely(str == NULL))
353 return NULL;
354
355 n = strlen(str);
356 ptr = ralloc_array(ctx, char, n + 1);
357 memcpy(ptr, str, n);
358 ptr[n] = '\0';
359 return ptr;
360 }
361
362 char *
363 ralloc_strndup(const void *ctx, const char *str, size_t max)
364 {
365 size_t n;
366 char *ptr;
367
368 if (unlikely(str == NULL))
369 return NULL;
370
371 n = strnlen(str, max);
372 ptr = ralloc_array(ctx, char, n + 1);
373 memcpy(ptr, str, n);
374 ptr[n] = '\0';
375 return ptr;
376 }
377
378 /* helper routine for strcat/strncat - n is the exact amount to copy */
379 static bool
380 cat(char **dest, const char *str, size_t n)
381 {
382 char *both;
383 size_t existing_length;
384 assert(dest != NULL && *dest != NULL);
385
386 existing_length = strlen(*dest);
387 both = resize(*dest, existing_length + n + 1);
388 if (unlikely(both == NULL))
389 return false;
390
391 memcpy(both + existing_length, str, n);
392 both[existing_length + n] = '\0';
393
394 *dest = both;
395 return true;
396 }
397
398
399 bool
400 ralloc_strcat(char **dest, const char *str)
401 {
402 return cat(dest, str, strlen(str));
403 }
404
405 bool
406 ralloc_strncat(char **dest, const char *str, size_t n)
407 {
408 /* Clamp n to the string length */
409 size_t str_length = strlen(str);
410 if (str_length < n)
411 n = str_length;
412
413 return cat(dest, str, n);
414 }
415
416 char *
417 ralloc_asprintf(const void *ctx, const char *fmt, ...)
418 {
419 char *ptr;
420 va_list args;
421 va_start(args, fmt);
422 ptr = ralloc_vasprintf(ctx, fmt, args);
423 va_end(args);
424 return ptr;
425 }
426
427 /* Return the length of the string that would be generated by a printf-style
428 * format and argument list, not including the \0 byte.
429 */
430 static size_t
431 printf_length(const char *fmt, va_list untouched_args)
432 {
433 int size;
434 char junk;
435
436 /* Make a copy of the va_list so the original caller can still use it */
437 va_list args;
438 va_copy(args, untouched_args);
439
440 #ifdef _WIN32
441 /* We need to use _vcsprintf to calculate the size as vsnprintf returns -1
442 * if the number of characters to write is greater than count.
443 */
444 size = _vscprintf(fmt, args);
445 (void)junk;
446 #else
447 size = vsnprintf(&junk, 1, fmt, args);
448 #endif
449 assert(size >= 0);
450
451 va_end(args);
452
453 return size;
454 }
455
456 char *
457 ralloc_vasprintf(const void *ctx, const char *fmt, va_list args)
458 {
459 size_t size = printf_length(fmt, args) + 1;
460
461 char *ptr = ralloc_size(ctx, size);
462 if (ptr != NULL)
463 vsnprintf(ptr, size, fmt, args);
464
465 return ptr;
466 }
467
468 bool
469 ralloc_asprintf_append(char **str, const char *fmt, ...)
470 {
471 bool success;
472 va_list args;
473 va_start(args, fmt);
474 success = ralloc_vasprintf_append(str, fmt, args);
475 va_end(args);
476 return success;
477 }
478
479 bool
480 ralloc_vasprintf_append(char **str, const char *fmt, va_list args)
481 {
482 size_t existing_length;
483 assert(str != NULL);
484 existing_length = *str ? strlen(*str) : 0;
485 return ralloc_vasprintf_rewrite_tail(str, &existing_length, fmt, args);
486 }
487
488 bool
489 ralloc_asprintf_rewrite_tail(char **str, size_t *start, const char *fmt, ...)
490 {
491 bool success;
492 va_list args;
493 va_start(args, fmt);
494 success = ralloc_vasprintf_rewrite_tail(str, start, fmt, args);
495 va_end(args);
496 return success;
497 }
498
499 bool
500 ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
501 va_list args)
502 {
503 size_t new_length;
504 char *ptr;
505
506 assert(str != NULL);
507
508 if (unlikely(*str == NULL)) {
509 // Assuming a NULL context is probably bad, but it's expected behavior.
510 *str = ralloc_vasprintf(NULL, fmt, args);
511 *start = strlen(*str);
512 return true;
513 }
514
515 new_length = printf_length(fmt, args);
516
517 ptr = resize(*str, *start + new_length + 1);
518 if (unlikely(ptr == NULL))
519 return false;
520
521 vsnprintf(ptr + *start, new_length + 1, fmt, args);
522 *str = ptr;
523 *start += new_length;
524 return true;
525 }
526
527 /***************************************************************************
528 * Linear allocator for short-lived allocations.
529 ***************************************************************************
530 *
531 * The allocator consists of a parent node (2K buffer), which requires
532 * a ralloc parent, and child nodes (allocations). Child nodes can't be freed
533 * directly, because the parent doesn't track them. You have to release
534 * the parent node in order to release all its children.
535 *
536 * The allocator uses a fixed-sized buffer with a monotonically increasing
537 * offset after each allocation. If the buffer is all used, another buffer
538 * is allocated, sharing the same ralloc parent, so all buffers are at
539 * the same level in the ralloc hierarchy.
540 *
541 * The linear parent node is always the first buffer and keeps track of all
542 * other buffers.
543 */
544
545 #define ALIGN_POT(x, y) (((x) + (y) - 1) & ~((y) - 1))
546
547 #define MIN_LINEAR_BUFSIZE 2048
548 #define SUBALLOC_ALIGNMENT sizeof(uintptr_t)
549 #define LMAGIC 0x87b9c7d3
550
551 struct linear_header {
552 #ifdef DEBUG
553 unsigned magic; /* for debugging */
554 #endif
555 unsigned offset; /* points to the first unused byte in the buffer */
556 unsigned size; /* size of the buffer */
557 void *ralloc_parent; /* new buffers will use this */
558 struct linear_header *next; /* next buffer if we have more */
559 struct linear_header *latest; /* the only buffer that has free space */
560
561 /* After this structure, the buffer begins.
562 * Each suballocation consists of linear_size_chunk as its header followed
563 * by the suballocation, so it goes:
564 *
565 * - linear_size_chunk
566 * - allocated space
567 * - linear_size_chunk
568 * - allocated space
569 * etc.
570 *
571 * linear_size_chunk is only needed by linear_realloc.
572 */
573 };
574
575 struct linear_size_chunk {
576 unsigned size; /* for realloc */
577 unsigned _padding;
578 };
579
580 typedef struct linear_header linear_header;
581 typedef struct linear_size_chunk linear_size_chunk;
582
583 #define LINEAR_PARENT_TO_HEADER(parent) \
584 (linear_header*) \
585 ((char*)(parent) - sizeof(linear_size_chunk) - sizeof(linear_header))
586
587 /* Allocate the linear buffer with its header. */
588 static linear_header *
589 create_linear_node(void *ralloc_ctx, unsigned min_size)
590 {
591 linear_header *node;
592
593 min_size += sizeof(linear_size_chunk);
594
595 if (likely(min_size < MIN_LINEAR_BUFSIZE))
596 min_size = MIN_LINEAR_BUFSIZE;
597
598 node = ralloc_size(ralloc_ctx, sizeof(linear_header) + min_size);
599 if (unlikely(!node))
600 return NULL;
601
602 #ifdef DEBUG
603 node->magic = LMAGIC;
604 #endif
605 node->offset = 0;
606 node->size = min_size;
607 node->ralloc_parent = ralloc_ctx;
608 node->next = NULL;
609 node->latest = node;
610 return node;
611 }
612
613 void *
614 linear_alloc_child(void *parent, unsigned size)
615 {
616 linear_header *first = LINEAR_PARENT_TO_HEADER(parent);
617 linear_header *latest = first->latest;
618 linear_header *new_node;
619 linear_size_chunk *ptr;
620 unsigned full_size;
621
622 assert(first->magic == LMAGIC);
623 assert(!latest->next);
624
625 size = ALIGN_POT(size, SUBALLOC_ALIGNMENT);
626 full_size = sizeof(linear_size_chunk) + size;
627
628 if (unlikely(latest->offset + full_size > latest->size)) {
629 /* allocate a new node */
630 new_node = create_linear_node(latest->ralloc_parent, size);
631 if (unlikely(!new_node))
632 return NULL;
633
634 first->latest = new_node;
635 latest->latest = new_node;
636 latest->next = new_node;
637 latest = new_node;
638 }
639
640 ptr = (linear_size_chunk *)((char*)&latest[1] + latest->offset);
641 ptr->size = size;
642 latest->offset += full_size;
643 return &ptr[1];
644 }
645
646 void *
647 linear_alloc_parent(void *ralloc_ctx, unsigned size)
648 {
649 linear_header *node;
650
651 if (unlikely(!ralloc_ctx))
652 return NULL;
653
654 size = ALIGN_POT(size, SUBALLOC_ALIGNMENT);
655
656 node = create_linear_node(ralloc_ctx, size);
657 if (unlikely(!node))
658 return NULL;
659
660 return linear_alloc_child((char*)node +
661 sizeof(linear_header) +
662 sizeof(linear_size_chunk), size);
663 }
664
665 void *
666 linear_zalloc_child(void *parent, unsigned size)
667 {
668 void *ptr = linear_alloc_child(parent, size);
669
670 if (likely(ptr))
671 memset(ptr, 0, size);
672 return ptr;
673 }
674
675 void *
676 linear_zalloc_parent(void *parent, unsigned size)
677 {
678 void *ptr = linear_alloc_parent(parent, size);
679
680 if (likely(ptr))
681 memset(ptr, 0, size);
682 return ptr;
683 }
684
685 void
686 linear_free_parent(void *ptr)
687 {
688 linear_header *node;
689
690 if (unlikely(!ptr))
691 return;
692
693 node = LINEAR_PARENT_TO_HEADER(ptr);
694 assert(node->magic == LMAGIC);
695
696 while (node) {
697 void *ptr = node;
698
699 node = node->next;
700 ralloc_free(ptr);
701 }
702 }
703
704 void
705 ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr)
706 {
707 linear_header *node;
708
709 if (unlikely(!ptr))
710 return;
711
712 node = LINEAR_PARENT_TO_HEADER(ptr);
713 assert(node->magic == LMAGIC);
714
715 while (node) {
716 ralloc_steal(new_ralloc_ctx, node);
717 node->ralloc_parent = new_ralloc_ctx;
718 node = node->next;
719 }
720 }
721
722 void *
723 ralloc_parent_of_linear_parent(void *ptr)
724 {
725 linear_header *node = LINEAR_PARENT_TO_HEADER(ptr);
726 assert(node->magic == LMAGIC);
727 return node->ralloc_parent;
728 }
729
730 void *
731 linear_realloc(void *parent, void *old, unsigned new_size)
732 {
733 unsigned old_size = 0;
734 ralloc_header *new_ptr;
735
736 new_ptr = linear_alloc_child(parent, new_size);
737
738 if (unlikely(!old))
739 return new_ptr;
740
741 old_size = ((linear_size_chunk*)old)[-1].size;
742
743 if (likely(new_ptr && old_size))
744 memcpy(new_ptr, old, MIN2(old_size, new_size));
745
746 return new_ptr;
747 }
748
749 /* All code below is pretty much copied from ralloc and only the alloc
750 * calls are different.
751 */
752
753 char *
754 linear_strdup(void *parent, const char *str)
755 {
756 unsigned n;
757 char *ptr;
758
759 if (unlikely(!str))
760 return NULL;
761
762 n = strlen(str);
763 ptr = linear_alloc_child(parent, n + 1);
764 if (unlikely(!ptr))
765 return NULL;
766
767 memcpy(ptr, str, n);
768 ptr[n] = '\0';
769 return ptr;
770 }
771
772 char *
773 linear_asprintf(void *parent, const char *fmt, ...)
774 {
775 char *ptr;
776 va_list args;
777 va_start(args, fmt);
778 ptr = linear_vasprintf(parent, fmt, args);
779 va_end(args);
780 return ptr;
781 }
782
783 char *
784 linear_vasprintf(void *parent, const char *fmt, va_list args)
785 {
786 unsigned size = printf_length(fmt, args) + 1;
787
788 char *ptr = linear_alloc_child(parent, size);
789 if (ptr != NULL)
790 vsnprintf(ptr, size, fmt, args);
791
792 return ptr;
793 }
794
795 bool
796 linear_asprintf_append(void *parent, char **str, const char *fmt, ...)
797 {
798 bool success;
799 va_list args;
800 va_start(args, fmt);
801 success = linear_vasprintf_append(parent, str, fmt, args);
802 va_end(args);
803 return success;
804 }
805
806 bool
807 linear_vasprintf_append(void *parent, char **str, const char *fmt, va_list args)
808 {
809 size_t existing_length;
810 assert(str != NULL);
811 existing_length = *str ? strlen(*str) : 0;
812 return linear_vasprintf_rewrite_tail(parent, str, &existing_length, fmt, args);
813 }
814
815 bool
816 linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start,
817 const char *fmt, ...)
818 {
819 bool success;
820 va_list args;
821 va_start(args, fmt);
822 success = linear_vasprintf_rewrite_tail(parent, str, start, fmt, args);
823 va_end(args);
824 return success;
825 }
826
827 bool
828 linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
829 const char *fmt, va_list args)
830 {
831 size_t new_length;
832 char *ptr;
833
834 assert(str != NULL);
835
836 if (unlikely(*str == NULL)) {
837 *str = linear_vasprintf(parent, fmt, args);
838 *start = strlen(*str);
839 return true;
840 }
841
842 new_length = printf_length(fmt, args);
843
844 ptr = linear_realloc(parent, *str, *start + new_length + 1);
845 if (unlikely(ptr == NULL))
846 return false;
847
848 vsnprintf(ptr + *start, new_length + 1, fmt, args);
849 *str = ptr;
850 *start += new_length;
851 return true;
852 }
853
854 /* helper routine for strcat/strncat - n is the exact amount to copy */
855 static bool
856 linear_cat(void *parent, char **dest, const char *str, unsigned n)
857 {
858 char *both;
859 unsigned existing_length;
860 assert(dest != NULL && *dest != NULL);
861
862 existing_length = strlen(*dest);
863 both = linear_realloc(parent, *dest, existing_length + n + 1);
864 if (unlikely(both == NULL))
865 return false;
866
867 memcpy(both + existing_length, str, n);
868 both[existing_length + n] = '\0';
869
870 *dest = both;
871 return true;
872 }
873
874 bool
875 linear_strcat(void *parent, char **dest, const char *str)
876 {
877 return linear_cat(parent, dest, str, strlen(str));
878 }