#include <string.h>
#include <stdint.h>
-/* Android defines SIZE_MAX in limits.h, instead of the standard stdint.h */
-#ifdef ANDROID
-#include <limits.h>
-#endif
-
/* Some versions of MinGW are missing _vscprintf's declaration, although they
* still provide the symbol in the import library. */
#ifdef __MINGW32__
return;
info = get_header(ptr);
- parent = get_header(new_ctx);
+ parent = new_ctx ? get_header(new_ctx) : NULL;
unlink_block(info);
for (child = old_info->child; child->next != NULL; child = child->next) {
child->parent = new_info;
}
+ child->parent = new_info;
/* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */
child->next = new_info->child;
- child->parent = new_info;
+ if (child->next)
+ child->next->prev = child;
new_info->child = old_info->child;
old_info->child = NULL;
}
bool
ralloc_strncat(char **dest, const char *str, size_t n)
{
- /* Clamp n to the string length */
- size_t str_length = strlen(str);
- if (str_length < n)
- n = str_length;
+ return cat(dest, str, strnlen(str, n));
+}
+
+bool
+ralloc_str_append(char **dest, const char *str,
+ size_t existing_length, size_t str_size)
+{
+ char *both;
+ assert(dest != NULL && *dest != NULL);
+
+ both = resize(*dest, existing_length + str_size + 1);
+ if (unlikely(both == NULL))
+ return false;
- return cat(dest, str, n);
+ memcpy(both + existing_length, str, str_size);
+ both[existing_length + str_size] = '\0';
+
+ *dest = both;
+
+ return true;
}
char *
linear_size_chunk *ptr;
unsigned full_size;
+#ifdef DEBUG
assert(first->magic == LMAGIC);
+#endif
assert(!latest->next);
size = ALIGN_POT(size, SUBALLOC_ALIGNMENT);
return;
node = LINEAR_PARENT_TO_HEADER(ptr);
+#ifdef DEBUG
assert(node->magic == LMAGIC);
+#endif
while (node) {
void *ptr = node;
return;
node = LINEAR_PARENT_TO_HEADER(ptr);
+#ifdef DEBUG
assert(node->magic == LMAGIC);
+#endif
while (node) {
ralloc_steal(new_ralloc_ctx, node);
ralloc_parent_of_linear_parent(void *ptr)
{
linear_header *node = LINEAR_PARENT_TO_HEADER(ptr);
+#ifdef DEBUG
assert(node->magic == LMAGIC);
+#endif
return node->ralloc_parent;
}