Created
February 15, 2021 16:40
-
-
Save begriffs/79919d3d9cf7bd7d9c7a2633e7ad1288 to your computer and use it in GitHub Desktop.
Might be a good idea, might not. Not yet tested
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
bool nmalloc(size_t n, void ***elts, ...) | |
{ | |
va_list ap; | |
*elts = malloc(n * sizeof **elts); | |
if (!*elts) | |
return false; | |
va_start(ap, elts); | |
for (size_t i = 0; i < n; i++) | |
{ | |
(*elts)[i] = malloc(va_arg(ap, size_t)); | |
if (!(*elts)[i]) | |
{ | |
for (size_t j = 0; j < i; j++) | |
free((*elts)[j]); | |
free(*elts); | |
return false; | |
} | |
} | |
va_end(ap); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment