gnulib-tool.py: Small refactoring.
[gnulib.git] / lib / pagealign_alloc.h
blob5460d79cc411b7bf10ca7989675b333405b208bc
1 /* Memory allocation aligned to system page boundaries.
3 Copyright (C) 2005, 2008, 2010-2024 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 /* This file uses _GL_ATTRIBUTE_ALLOC_SIZE, _GL_ATTRIBUTE_DEALLOC,
22 _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_NONNULL,
23 _GL_ATTRIBUTE_RETURNS_NONNULL. */
24 #if !_GL_CONFIG_H_INCLUDED
25 # error "Please include config.h first."
26 #endif
28 #include <stddef.h>
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
35 /* Free a memory block.
36 PTR must be a non-NULL pointer returned by pagealign_alloc or
37 pagealign_xalloc. */
38 extern void pagealign_free (void *ptr)
39 _GL_ATTRIBUTE_NONNULL ((1));
41 /* Allocate a block of memory of SIZE bytes, aligned on a system page
42 boundary.
43 If SIZE is not a multiple of the system page size, it will be rounded up
44 to the next multiple.
45 Return a pointer to the start of the memory block. Upon allocation failure,
46 return NULL and set errno. */
47 extern void *pagealign_alloc (size_t size)
48 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (pagealign_free, 1)
49 _GL_ATTRIBUTE_ALLOC_SIZE ((1));
51 /* Like pagealign_alloc, except it exits the program if the allocation
52 fails. */
53 extern void *pagealign_xalloc (size_t size)
54 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (pagealign_free, 1)
55 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
58 #ifdef __cplusplus
60 #endif
62 #endif /* _PAGEALIGN_ALLOC_H */