os: move alloc functions to separate source file
Reduce the massive os/utils.c a little bit by moving out the alloc functions to their own source file. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1336>
This commit is contained in:
parent
4705fa933a
commit
3e9ac852bc
|
@ -0,0 +1,60 @@
|
||||||
|
/* SPDX-License-Identifier: MIT OR X11
|
||||||
|
*
|
||||||
|
* Copyright © 1987, 1998 The Open Group
|
||||||
|
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
||||||
|
*/
|
||||||
|
#include <dix-config.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
void *
|
||||||
|
XNFalloc(unsigned long amount)
|
||||||
|
{
|
||||||
|
void *ptr = malloc(amount);
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
FatalError("Out of memory");
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The original XNFcalloc was used with the xnfcalloc macro which multiplied
|
||||||
|
* the arguments at the call site without allowing calloc to check for overflow.
|
||||||
|
* XNFcallocarray was added to fix that without breaking ABI.
|
||||||
|
*/
|
||||||
|
void *
|
||||||
|
XNFcalloc(unsigned long amount)
|
||||||
|
{
|
||||||
|
return XNFcallocarray(1, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
XNFcallocarray(size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
void *ret = calloc(nmemb, size);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
FatalError("XNFcalloc: Out of memory");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
XNFrealloc(void *ptr, unsigned long amount)
|
||||||
|
{
|
||||||
|
void *ret = realloc(ptr, amount);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
FatalError("XNFrealloc: Out of memory");
|
||||||
|
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;
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
srcs_os = [
|
srcs_os = [
|
||||||
'WaitFor.c',
|
'WaitFor.c',
|
||||||
'access.c',
|
'access.c',
|
||||||
|
'alloc.c',
|
||||||
'auth.c',
|
'auth.c',
|
||||||
'backtrace.c',
|
'backtrace.c',
|
||||||
'client.c',
|
'client.c',
|
||||||
|
|
50
os/utils.c
50
os/utils.c
|
@ -1131,56 +1131,6 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
|
||||||
#endif /* TCPCONN */
|
#endif /* TCPCONN */
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
|
||||||
XNFalloc(unsigned long amount)
|
|
||||||
{
|
|
||||||
void *ptr = malloc(amount);
|
|
||||||
|
|
||||||
if (!ptr)
|
|
||||||
FatalError("Out of memory");
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The original XNFcalloc was used with the xnfcalloc macro which multiplied
|
|
||||||
* the arguments at the call site without allowing calloc to check for overflow.
|
|
||||||
* XNFcallocarray was added to fix that without breaking ABI.
|
|
||||||
*/
|
|
||||||
void *
|
|
||||||
XNFcalloc(unsigned long amount)
|
|
||||||
{
|
|
||||||
return XNFcallocarray(1, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
XNFcallocarray(size_t nmemb, size_t size)
|
|
||||||
{
|
|
||||||
void *ret = calloc(nmemb, size);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
FatalError("XNFcalloc: Out of memory");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
XNFrealloc(void *ptr, unsigned long amount)
|
|
||||||
{
|
|
||||||
void *ret = realloc(ptr, amount);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
FatalError("XNFrealloc: Out of memory");
|
|
||||||
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