Skip to content
Snippets Groups Projects
Commit 690083b4 authored by Timo Teräs's avatar Timo Teräs
Browse files

portability: add reallocarray

parent a50c67d6
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ check_functions = [
['mknodat', 'mknodat.c', 'NEED_MKNODAT', 'sys/stat.h'],
['pipe2', 'pipe2.c', 'NEED_PIPE2', 'unistd.h'],
['qsort_r', 'qsort_r.c', 'NEED_QSORT_R', 'stdlib.h'],
['reallocarray', 'reallocarray.c', 'NEED_REALLOCARRAY', 'stdlib.h'],
['strchrnul', 'strchrnul.c', 'NEED_STRCHRNUL', 'string.h'],
['strlcpy', 'strlcpy.c', 'NEED_STRLCPY', 'string.h'],
]
......
#include <errno.h>
#include <stdlib.h>
void *reallocarray(void *ptr, size_t m, size_t n)
{
if (n && m > -1 / n) {
errno = ENOMEM;
return 0;
}
return realloc(ptr, m * n);
}
#pragma once
#include_next <stdlib.h>
#ifdef NEED_REALLOCARRAY
void *reallocarray(void *ptr, size_t m, size_t n);
#endif
#ifdef NEED_QSORT_R
void qsort_r(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *, void *),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment