ci: Check for DDXen to be built
[xserver.git] / os / alloc.c
blobd808b0fe82362f6797a9837679240fdb893fc4c6
1 /* SPDX-License-Identifier: MIT OR X11
3 * Copyright © 1987, 1998 The Open Group
4 * Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
5 */
6 #include <dix-config.h>
8 #include <stdlib.h>
10 #include "os.h"
12 void *
13 XNFalloc(unsigned long amount)
15 void *ptr = malloc(amount);
17 if (!ptr)
18 FatalError("Out of memory");
19 return ptr;
22 /* The original XNFcalloc was used with the xnfcalloc macro which multiplied
23 * the arguments at the call site without allowing calloc to check for overflow.
24 * XNFcallocarray was added to fix that without breaking ABI.
26 void *
27 XNFcalloc(unsigned long amount)
29 return XNFcallocarray(1, amount);
32 void *
33 XNFcallocarray(size_t nmemb, size_t size)
35 void *ret = calloc(nmemb, size);
37 if (!ret)
38 FatalError("XNFcalloc: Out of memory");
39 return ret;
42 void *
43 XNFrealloc(void *ptr, unsigned long amount)
45 void *ret = realloc(ptr, amount);
47 if (!ret)
48 FatalError("XNFrealloc: Out of memory");
49 return ret;
52 void *
53 XNFreallocarray(void *ptr, size_t nmemb, size_t size)
55 void *ret = reallocarray(ptr, nmemb, size);
57 if (!ret)
58 FatalError("XNFreallocarray: Out of memory");
59 return ret;