Add no-fail equivalents of allocarray & reallocarray
v2: Remove extra 's' from comment Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
c213b29d14
commit
ae75d50395
|
@ -76,6 +76,8 @@ typedef struct _NewClientRec *NewClientPtr;
|
||||||
#define xnfstrdup(s) XNFstrdup(s)
|
#define xnfstrdup(s) XNFstrdup(s)
|
||||||
|
|
||||||
#define xallocarray(num, size) reallocarray(NULL, (num), (size))
|
#define xallocarray(num, size) reallocarray(NULL, (num), (size))
|
||||||
|
#define xnfallocarray(num, size) XNFreallocarray(NULL, (num), (size))
|
||||||
|
#define xnfreallocarray(ptr, num, size) XNFreallocarray((ptr), (num), (size))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -240,6 +242,13 @@ XNFcallocarray(size_t nmemb, size_t size);
|
||||||
extern _X_EXPORT void *
|
extern _X_EXPORT void *
|
||||||
XNFrealloc(void * /*ptr */ , unsigned long /*amount */ );
|
XNFrealloc(void * /*ptr */ , unsigned long /*amount */ );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function reallocarray(3)s passed buffer, terminating the server if
|
||||||
|
* there is not enough memory or the arguments overflow when multiplied.
|
||||||
|
*/
|
||||||
|
extern _X_EXPORT void *
|
||||||
|
XNFreallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function strdup(3)s passed string. The only difference from the library
|
* This function strdup(3)s passed string. The only difference from the library
|
||||||
* function that it is safe to pass NULL, as NULL will be returned.
|
* function that it is safe to pass NULL, as NULL will be returned.
|
||||||
|
|
10
os/utils.c
10
os/utils.c
|
@ -1158,6 +1158,16 @@ XNFrealloc(void *ptr, unsigned long amount)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
XNFreallocarray(void *ptr, size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
void *ret = reallocarray(ptr, nmemb, size);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
FatalError("XNFreallocarray: Out of memory");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
Xstrdup(const char *s)
|
Xstrdup(const char *s)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user