dynarr - yet another simple C dynamic array library I wrote my own dynamic array library for C as I was not happy with the others I found. It is very crude but the basic logic should be correct, it mainly revolves making realloc easier to use and avoiding repetitive code.
Please offer your suggestions and criticisms!
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define DYNARRAY_H_INCREMENT 50

typedef struct dynarr dynarr;

struct dynarr {
    void *actual;
    size_t size;
    size_t e_size;
    size_t occupied;
    size_t increment;
    void (*mem_callback)(dynarr *);
};

void *dynarr_nomen(dynarr *array) {
    if (array-&gt;mem_callback) array-&gt;mem_callback(array);
    array-&gt;actual = NULL;
    array-&gt;occupied = 0;
    return NULL;
}

dynarr dynarr_init_full(size_t e_size, size_t increment, void (*mem_callback)(dynarr *)) {
    return (dynarr){
        .actual = NULL,
        .size = 0,
        .e_size = e_size,
        .occupied = 0,
        .increment = increment,
        .mem_callback = mem_callback,
    };
}

dynarr dynarr_init(size_t element_size) {
    return dynarr_init_full(element_size, DYNARRAY_H_INCREMENT, NULL);
}

void *dynarr_push(dynarr *array, void *data) {
    if (array-&gt;occupied == array-&gt;size) {
        // Array is full
        // Increase size
        size_t new_real_size = (array-&gt;size + array-&gt;increment) * array-&gt;e_size;
        array-&gt;actual = realloc(array-&gt;actual, new_real_size);
        if (!array-&gt;actual) return dynarr_nomen(array);
        array-&gt;size += array-&gt;increment;
    }
    
    // Copy data
    char *charr = (char *) array-&gt;actual;
    memcpy(charr + array-&gt;occupied++ * array-&gt;e_size, data, array-&gt;e_size);
    
    return array-&gt;actual;
}

void *dynarr_get(dynarr *array, size_t *size) {
    if (size) *size = array-&gt;occupied;
    return array-&gt;actual;
}

void *dynarr_compact(dynarr *array) {
    if (array-&gt;occupied == array-&gt;size) goto end;
    array-&gt;actual = realloc(array-&gt;actual, array-&gt;occupied * array-&gt;e_size);
    if (!array-&gt;actual) return dynarr_nomen(array);
    array-&gt;size = array-&gt;occupied;
    end: return array-&gt;actual;
}

void dynarr_free(dynarr *array) {
    free(array-&gt;actual);
    array-&gt;actual = NULL;
    array-&gt;occupied = 0;
}

I intend to split declarations into a separate header in the future, I have kept it as a simple single source file for now.
I also made a very crude example program which could definitely use some major improvements... or maybe it can even be replaced by something else.
#include &lt;signal.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &quot;dynarr.c&quot;

volatile sig_atomic_t signaled = false;

void trap_interrupt(int sig) {
    signaled = true;
}

int main(void) {
    signal(SIGINT, trap_interrupt); 
    
    int c;
    char data;
    dynarr input = dynarr_init(sizeof data);
    
    for (;;) {
        if (signaled) break;
        c = getc(stdin);
        if (c == EOF) break;
        data = c;
        if (!dynarr_push(&amp;input, &amp;data)) {
            puts(&quot;Ran out of memory!!!&quot;);
            break;
        };
    }
    
    size_t count;
    dynarr_get(&amp;input, &amp;count);
    printf(&quot;Stored %zu bytes in dynamic array\n&quot;, count);
    
    return EXIT_SUCCESS;
}
Regarding incrementing by a fixed amount
The problem with resizing the storage by a fixed amount each time you reach capacity is that it effectively makes pushing a new element to the array an \$\mathcal{O}(N)\$ operation. If you instead double the amount of storage each time, pushing will be amortized \$\mathcal{O}(1)\$.
The drawback of doubling the capacity each time is that you might waste more memory than if you only increase it by fixed amounts. However, unless you are constrained by the amount of memory you have, I would recommend the doubling approach.
Memory leaks
Your code leaks memory when running out of memory. If you call realloc(), but it returns NULL, the original memory is not freed and still valid. So instead of unconditionally overwriting array-&gt;actual, you should write something like:
void *new_actual = realloc(array-&gt;actual, new_real_size);

if (!new_actual) {
    free(array-&gt;actual);
    return dynarray_nomem(array-&gt;actual);
}

array-&gt;actual = new_actual;
array-&gt;size = new_real_size;

Alternatively, and perhaps even better, is to just keep the original data and return NULL, and let the caller worry about whether they want to destroy the array or want to keep using it:
void *new_actual = realloc(array-&gt;actual, new_real_size);

if (!new_actual) {
    return NULL;
}
...

(Re)move the callback
I don't see the point of having a callback function that is called when memory allocation failed, if the caller already has to check the return value of dynarray_push() and dynarray_compact(). I would just remove this unnecessary complexity.

This is an useful feature which can be used to avoid error checking for each push, instead of the caller can specify a callback function which would use something like longjmp to initiate a no memory exit sequence.

If you want this, I recommend you move the mem_callback pointer out of struct dynarr, and make it a global variable named dynarr_mem_callback.
Consider returning a pointer to the pushed element
It would be much more useful if dynarray_push() would return a pointer to the element that was just pushed, instead of a pointer to the start of the array. There is already dynarray_get() to get a pointer to the start, but see below.
Add a function to get a pointer to a specific element
Since it is likely that a user might want to access a specific element in the dynamic array, it would be helpful to add a function that does that in one go. In fact, I would name that function dynarray_get():
void *dynarray_get(dynarray *array, size_t offset) {
    // Bounds checking, has a performance impact though:
    if (offset &gt;= array-&gt;occupied)
        return NULL;

    return (char *)array-&gt;actual + offset * array-&gt;e_size;
}

And add separate functions dynarray_data() and dynarray_size() to get a pointer to the underlying storage and the number of elements respectively.
Avoid using goto
It is quite easy to avoid the goto statement in dynarray_compact(), just replace it with return array-&gt;actual. Even better would be to just unconditionally call realloc(), since it is unlikely that size and occupied will be the same, and this is not a function that would be called very often anyway, so it is not performance critical:
void *dynarr_compact(dynarr *array) {
    void *new_actual = realloc(array-&gt;actual, array-&gt;occupied * array-&gt;e_size);

    if (new_actual) {
        array-&gt;actual = new_actual;
        array-&gt;size = array-&gt;occupied;
    }

    return array-&gt;actual;
}