]> granicus.if.org Git - strace/blobdiff - xmalloc.c
Remove linux/ptp_clock.h
[strace] / xmalloc.c
index 8ec475a154dcffa5b025af7fe3ae9c883673af52..4a318b6154f3254f803b5d20fbad7b7676449994 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -89,6 +89,28 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
        return p;
 }
 
+void *
+xgrowarray(void *const ptr, size_t *const nmemb, const size_t memb_size)
+{
+       /* this is the same value as glibc DEFAULT_MXFAST */
+       enum { DEFAULT_ALLOC_SIZE = 64 * SIZEOF_LONG / 4 };
+
+       size_t grow_memb;
+
+       if (ptr == NULL)
+               grow_memb = *nmemb ? 0 :
+                       (DEFAULT_ALLOC_SIZE + memb_size - 1) / memb_size;
+       else
+               grow_memb = (*nmemb >> 1) + 1;
+
+       if ((*nmemb + grow_memb) < *nmemb)
+               die_out_of_memory();
+
+       *nmemb += grow_memb;
+
+       return xreallocarray(ptr, *nmemb, memb_size);
+}
+
 char *
 xstrdup(const char *str)
 {