Created
June 8, 2015 19:39
-
-
Save sortie/9bc9d66b170c9b625890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static bool array_add(void*** array_ptr, | |
size_t* used_ptr, | |
size_t* length_ptr, | |
void* value) | |
{ | |
void** array; | |
memcpy(&array, array_ptr, sizeof(array)); | |
if ( *used_ptr == *length_ptr ) | |
{ | |
size_t new_length = 2 * *length_ptr; | |
if ( !new_length ) | |
new_length = 16; | |
size_t new_size = new_length * sizeof(void*); | |
void** new_array = (void**) realloc(array, new_size); | |
if ( !new_array ) | |
return false; | |
array = new_array; | |
memcpy(array_ptr, &array, sizeof(array)); | |
*length_ptr = new_length; | |
} | |
memcpy(array + (*used_ptr)++, &value, sizeof(value)); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment