*-map tests: Fix compilation error.
[gnulib.git] / lib / pagealign_alloc.h
blob24065bc707d3da36f3e31d737f2ac56cd96be783
1 /* Memory allocation aligned to system page boundaries.
3 Copyright (C) 2005, 2008, 2010-2019 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef _PAGEALIGN_ALLOC_H
19 # define _PAGEALIGN_ALLOC_H
21 # include <stddef.h>
23 #if ! defined __clang__ && \
24 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
25 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
26 #else
27 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
28 #endif
30 /* Allocate a block of memory of SIZE bytes, aligned on a system page
31 boundary.
32 If SIZE is not a multiple of the system page size, it will be rounded up
33 to the next multiple.
34 Return a pointer to the start of the memory block. Upon allocation failure,
35 return NULL and set errno. */
36 extern void *pagealign_alloc (size_t size)
37 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
39 /* Like pagealign_alloc, except it exits the program if the allocation
40 fails. */
41 extern void *pagealign_xalloc (size_t size)
42 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
44 /* Free a memory block.
45 PTR must be a non-NULL pointer returned by pagealign_alloc or
46 pagealign_xalloc. */
47 extern void pagealign_free (void *ptr);
49 #endif /* _PAGEALIGN_ALLOC_H */