1/*
2 * Copyright 2023, Haiku Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _KERNEL_STDLIB_H
6#define _KERNEL_STDLIB_H
7
8/*
9	When building the kernel, the bootloader or kernel add-ons, the Haiku build system passes the
10	`-ffreestanding` argument to GCC, in order to make sure that only the C++ language features can
11	be used that do not require the C/C++ standard library.
12	The Haiku kernel and boot loaders include part of the standard library in the kernel/boot
13	loader. It uses the C/C++ standard library headers (like this one) to expose the
14	functions/features that are included.
15
16	If we are building for the kernel or the boot loader, the logic below will tell GCC's C++
17	headers to include the underlying posix headers, so that the kernel, the boot loader and kernel
18	add-ons can link to the symbols defined in them.
19
20	When we are NOT building for the kernel or the boot loader, we fall back to GCC's default
21	behaviour.
22*/
23
24#if (defined(_KERNEL_MODE) || defined(_BOOT_MODE)) && !defined(_GLIBCXX_INCLUDE_NEXT_C_HEADERS)
25# define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
26# include_next <stdlib.h>
27# undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
28#else
29# include_next <stdlib.h>
30#endif
31
32
33#endif // _KERNEL_STDLIB_H
34