diff options
Diffstat (limited to 'include/iprt/nocrt')
53 files changed, 7166 insertions, 0 deletions
diff --git a/include/iprt/nocrt/Makefile.kup b/include/iprt/nocrt/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/include/iprt/nocrt/Makefile.kup diff --git a/include/iprt/nocrt/algorithm b/include/iprt/nocrt/algorithm new file mode 100644 index 00000000..bf6102f8 --- /dev/null +++ b/include/iprt/nocrt/algorithm @@ -0,0 +1,164 @@ +/** @file + * IPRT / No-CRT - Minimal C++ algorithm header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_algorithm +#define VBOX_INCLUDED_SRC_nocrt_algorithm +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4643) /* warning C4643: Forward declaring 'ios_base' in namespace std is not permitted by the C++ Standard */ +#endif + +namespace std +{ + /** + * Swap the values pointed to by the two references. + */ + template<typename a_Type> + void swap(a_Type &a_rObj1, a_Type &a_rObj2) + { + a_Type Tmp(a_rObj1); + a_rObj1 = a_rObj2; + a_rObj2 = Tmp; + } + + /** + * Swap the values pointed to by two forward iterators. + */ + template<typename a_ForwardIt1, typename a_ForwardIt2> + void iter_swap(a_ForwardIt1 a_It1, a_ForwardIt2 a_It2) + { + swap(*a_It1, *a_It2); + } + + template<typename a_RandomIt> + void sort(a_RandomIt a_ItBegin, a_RandomIt a_ItEnd) + { + /* Note! Using shell sort here because it's tiny and we've got code for it. */ + /** @todo replace with faster code. */ + + /* Anything worth sorting? */ + std::size_t const cElements = a_ItEnd - a_ItBegin; + if (cElements >= 1) + { + /* Loop on decreasing gap, ending with 1: */ + std::size_t cGap = (cElements + 1) / 2; + while (cGap > 0) + { + /* Iterate from cGap till the end: */ + for (std::size_t i = cGap; i < cElements; i++) + { + /* Find the best suitable location for the item at 'i' comparing + backwards in steps of 'cGap', swapping the item at 'i' with the + one at '-cGap*j' if it's smaller, stopping if it's larger. + + Note! Original algorithm would make a copy of the item, this version + avoids extra copies of sorted items at the cost of extra copies + when dealing with unsorted ones a small cGaps values. */ + a_RandomIt ItCur = a_ItBegin + i; + size_t j = i; + do + { + j -= cGap; + a_RandomIt ItAtGap = a_ItBegin + j; + if (*ItAtGap < *ItCur) + break; + std::iter_swap(ItAtGap, ItCur); + ItCur = ItAtGap; + } while (j >= cGap); + } + + /* This does not generate the most optimal gap sequence, but it has the + advantage of being simple and avoid floating point. */ + cGap /= 2; + } + } + } + + template<typename a_RandomIt, typename a_FnCompareType> + void sort(a_RandomIt a_ItBegin, a_RandomIt a_ItEnd, a_FnCompareType a_fnComp) + { + /* Note! Using shell sort here because it's tiny and we've got code for it. */ + /** @todo replace with faster code. */ + + /* Anything worth sorting? */ + std::size_t const cElements = a_ItEnd - a_ItBegin; + if (cElements >= 1) + { + /* Loop on decreasing gap, ending with 1: */ + std::size_t cGap = (cElements + 1) / 2; + while (cGap > 0) + { + /* Iterate from cGap till the end: */ + for (std::size_t i = cGap; i < cElements; i++) + { + /* Find the best suitable location for the item at 'i' comparing + backwards in steps of 'cGap', swapping the item at 'i' with the + one at '-cGap*j' if it's smaller, stopping if it's larger. + + Note! Original algorithm would make a copy of the item, this version + avoids extra copies of sorted items at the cost of extra copies + when dealing with unsorted ones a small cGaps values. */ + a_RandomIt ItCur = a_ItBegin + i; + size_t j = i; + do + { + j -= cGap; + a_RandomIt ItAtGap = a_ItBegin + j; + if (a_fnComp(*ItAtGap, *ItCur)) + break; + std::iter_swap(ItAtGap, ItCur); + ItCur = ItAtGap; + } while (j >= cGap); + } + + /* This does not generate the most optimal gap sequence, but it has the + advantage of being simple and avoid floating point. */ + cGap /= 2; + } + } + } + +} + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +#endif /* !VBOX_INCLUDED_SRC_nocrt_algorithm */ + diff --git a/include/iprt/nocrt/amd64/Makefile.kup b/include/iprt/nocrt/amd64/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/include/iprt/nocrt/amd64/Makefile.kup diff --git a/include/iprt/nocrt/amd64/math.h b/include/iprt/nocrt/amd64/math.h new file mode 100644 index 00000000..19bdea78 --- /dev/null +++ b/include/iprt/nocrt/amd64/math.h @@ -0,0 +1,115 @@ +/** @file + * IPRT / No-CRT - math.h, AMD inlined functions. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_amd64_math_h +#define IPRT_INCLUDED_nocrt_amd64_math_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/asm.h> + + +#if RT_INLINE_ASM_GNU_STYLE && defined(__SSE__) + +DECLINLINE(long double) inline_atan2l(long double lrd1, long double lrd2) +{ + long double lrdResult; + __asm__ __volatile__("fpatan" + : "=t" (lrdResult) + : "u" (lrd1), + "0" (lrd2) + : "st(1)"); + return lrdResult; +} + +DECLINLINE(long double) inline_rintl(long double lrd) +{ + long double lrdResult; + __asm__ __volatile__("frndint" + : "=t" (lrdResult) + : "0" (lrd)); + return lrdResult; +} + +DECLINLINE(float) inline_rintf(float rf) +{ + return (float)inline_rintl(rf); +} + +DECLINLINE(double) inline_rint(double rd) +{ + return (double)inline_rintl(rd); +} + +DECLINLINE(long double) inline_sqrtl(long double lrd) +{ + long double lrdResult; + __asm__ __volatile__("fsqrt" + : "=t" (lrdResult) + : "0" (lrd)); + return lrdResult; +} + +DECLINLINE(float) inline_sqrtf(float rf) +{ + return (float)inline_sqrtl(rf); +} + +DECLINLINE(double) inline_sqrt(double rd) +{ + return (double)inline_sqrtl(rd); +} + + +# undef atan2l +# define atan2l(lrd1, lrd2) inline_atan2l(lrd1, lrd2) +# undef rint +# define rint(rd) inline_rint(rd) +# undef rintf +# define rintf(rf) inline_rintf(rf) +# undef rintl +# define rintl(lrd) inline_rintl(lrd) +# undef sqrt +# define sqrt(rd) inline_sqrt(rd) +# undef sqrtf +# define sqrtf(rf) inline_sqrtf(rf) +# undef sqrtl +# define sqrtl(lrd) inline_sqrtl(lrd) + +#endif /* RT_INLINE_ASM_GNU_STYLE */ + +#endif /* !IPRT_INCLUDED_nocrt_amd64_math_h */ + diff --git a/include/iprt/nocrt/assert.h b/include/iprt/nocrt/assert.h new file mode 100644 index 00000000..987db7df --- /dev/null +++ b/include/iprt/nocrt/assert.h @@ -0,0 +1,57 @@ +/** @file + * IPRT / No-CRT - Our own assert.h header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_assert_h +#define IPRT_INCLUDED_nocrt_assert_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/assert.h> + +DECL_FORCE_INLINE(void) rtCrtAssertPanic(void) +{ + RTAssertPanic(); +} + +/* Mesa uses assert() in such a way that we must not have any 'do {} while' + wrappers in the expansion, so we partially cook our own assert here but + using the standard iprt/assert.h building blocks. */ +#define assert(a_Expr) (RT_LIKELY(!!(a_Expr)) ? (void)0 \ + : RTAssertMsg1Weak((const char *)0, __LINE__, __FILE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__), \ + rtCrtAssertPanic(), (void)0 ) + +#endif /* !IPRT_INCLUDED_nocrt_assert_h */ + diff --git a/include/iprt/nocrt/cassert b/include/iprt/nocrt/cassert new file mode 100644 index 00000000..3315a4bd --- /dev/null +++ b/include/iprt/nocrt/cassert @@ -0,0 +1,49 @@ +/** @file + * IPRT / No-CRT - Minimal C++ cassert header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_cassert +#define VBOX_INCLUDED_SRC_nocrt_cassert +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/assert.h> + +namespace std +{ +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_cassert */ + diff --git a/include/iprt/nocrt/compiler/compiler.h b/include/iprt/nocrt/compiler/compiler.h new file mode 100644 index 00000000..c2ca1d80 --- /dev/null +++ b/include/iprt/nocrt/compiler/compiler.h @@ -0,0 +1,52 @@ +/** @file + * IPRT / No-CRT - compiler specifics. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_compiler_compiler_h +#define IPRT_INCLUDED_nocrt_compiler_compiler_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#ifdef __GNUC__ +# include <iprt/nocrt/compiler/gcc.h> +#elif defined(_MSC_VER) +# include <iprt/nocrt/compiler/msc.h> +#elif defined(__WATCOMC__) +# include <iprt/nocrt/compiler/watcom.h> +#else +# error "Unsupported compiler." +#endif + +#endif /* !IPRT_INCLUDED_nocrt_compiler_compiler_h */ diff --git a/include/iprt/nocrt/compiler/gcc.h b/include/iprt/nocrt/compiler/gcc.h new file mode 100644 index 00000000..91c1d5a8 --- /dev/null +++ b/include/iprt/nocrt/compiler/gcc.h @@ -0,0 +1,134 @@ +/** @file + * IPRT / No-CRT - GCC specifics. + * + * A quick hack for freebsd where there are no separate location + * for compiler specific headers like on linux, mingw, os2, ++. + * This file will be cleaned up later... + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_compiler_gcc_h +#define IPRT_INCLUDED_nocrt_compiler_gcc_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + + +/* stddef.h */ +#ifdef __PTRDIFF_TYPE__ +typedef __PTRDIFF_TYPE__ ptrdiff_t; +#elif ARCH_BITS == 32 +typedef int32_t ptrdiff_t; +#elif ARCH_BITS == 64 +typedef int64_t ptrdiff_t; +#else +# error "ARCH_BITS is undefined or incorrect." +#endif +#define _PTRDIFF_T_DECLARED + +#ifdef __SIZE_TYPE__ +typedef __SIZE_TYPE__ size_t; +#elif ARCH_BITS == 32 +typedef uint32_t size_t; +#elif ARCH_BITS == 64 +typedef uint64_t size_t; +#else +# error "ARCH_BITS is undefined or incorrect." +#endif +#define _SIZE_T_DECLARED + +#ifndef __cplusplus +# ifdef __WCHAR_TYPE__ +typedef __WCHAR_TYPE__ wchar_t; +# elif defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) +typedef uint16_t wchar_t; +# else +typedef int wchar_t; +# endif +# define _WCHAR_T_DECLARED +#endif + +#ifdef __WINT_TYPE__ +typedef __WINT_TYPE__ wint_t; +#else +typedef unsigned int wint_t; +#endif +#define _WINT_T_DECLARED + +#ifndef NULL +# ifdef __cplusplus +# define NULL 0 +# else +# define NULL ((void *)0) +# endif +#endif + + +#ifndef offsetof +# if defined(__cplusplus) && defined(__offsetof__) +# define offsetof(type, memb) + (__offsetof__ (reinterpret_cast<size_t>(&reinterpret_cast<const volatile char &>(static_cast<type *>(0)->memb))) ) +# else +# define offsetof(type, memb) ((size_t)&((type *)0)->memb) +# endif +#endif + + +/* sys/types.h */ +#ifdef __SSIZE_TYPE__ +typedef __SSIZE_TYPE__ ssize_t; +#elif ARCH_BITS == 32 +typedef int32_t ssize_t; +#elif ARCH_BITS == 64 +typedef int64_t ssize_t; +#else +# define ARCH_BITS 123123 +# error "ARCH_BITS is undefined or incorrect." +#endif +#define _SSIZE_T_DECLARED + + +/* stdarg.h */ +typedef __builtin_va_list va_list; +#if __GNUC__ == 3 \ + && __GNUC_MINOR__ == 2 +# define va_start(va, arg) __builtin_stdarg_start(va, arg) +#else +# define va_start(va, arg) __builtin_va_start(va, arg) +#endif +#define va_end(va) __builtin_va_end(va) +#define va_arg(va, type) __builtin_va_arg(va, type) +#define va_copy(dst, src) __builtin_va_copy(dst, src) + + +#endif /* !IPRT_INCLUDED_nocrt_compiler_gcc_h */ diff --git a/include/iprt/nocrt/compiler/msc.h b/include/iprt/nocrt/compiler/msc.h new file mode 100644 index 00000000..be81fffc --- /dev/null +++ b/include/iprt/nocrt/compiler/msc.h @@ -0,0 +1,62 @@ +/** @file + * IPRT / No-CRT - MSC specifics. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_compiler_msc_h +#define IPRT_INCLUDED_nocrt_compiler_msc_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + + +/* stddef.h */ +#if !defined(_MT) && !defined(_DLL) && _MSC_VER < 1400 +# define errno msvcrt_errno +#endif +#if _MSC_VER >= 1900 +# include <vcruntime.h> +#else +# include <../include/stddef.h> +#endif +#undef errno + +#undef ssize_t +typedef intptr_t ssize_t; + + +/* stdarg.h */ +#include <../include/stdarg.h> + +#endif /* !IPRT_INCLUDED_nocrt_compiler_msc_h */ + diff --git a/include/iprt/nocrt/compiler/watcom.h b/include/iprt/nocrt/compiler/watcom.h new file mode 100644 index 00000000..507b66dc --- /dev/null +++ b/include/iprt/nocrt/compiler/watcom.h @@ -0,0 +1,108 @@ +/** @file + * IPRT / No-CRT - Open Watcom specifics. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_compiler_watcom_h +#define IPRT_INCLUDED_nocrt_compiler_watcom_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/cdefs.h> + +/* stddef.h for size_t and such */ +#if 0 +# include <../h/stddef.h> + +# ifndef _SSIZE_T_DEFINED_ +# define _SSIZE_T_DEFINED_ +typedef signed int ssize_t; +# endif + +#else + +# define _SIZE_T_DEFINED_ +# define __size_t +typedef unsigned size_t; +typedef size_t _w_size_t; + +# define _SSIZE_T_DEFINED_ +# define __ssize_t +typedef signed int ssize_t; + +# define _RSIZE_T_DEFINED +typedef size_t rsize_t; + +# define _PTRDIFF_T_DEFINED_ +# ifdef __HUGE__ +typedef long ptrdiff_t; +# else +typedef int ptrdiff_t; +# endif + +# ifndef _WCHAR_T_DEFINED /* predefined in C++ mode? */ +# define _WCHAR_T_DEFINED +typedef unsigned short wchar_t; +# endif + +# ifndef NULL +# ifndef __cplusplus +# define NULL ((void *)0) +# elif defined(__SMALL__) || defined(__MEDIUM__) || !defined(_M_I86) +# define NULL (0) +# else +# define NULL (0L) +# endif +# endif + +# define offsetof(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member) + +# if defined(_M_I86) && (defined(__SMALL__) || defined(__MEDIUM__)) +typedef int intptr_t; +typedef unsigned int uintptr_t; +# elif defined(_M_I86) || (!defined(__COMPACT__) && !defined(__LARGE__)) +typedef long intptr_t; +typedef unsigned long uintptr_t; +# else /* 32-bit compile using far data pointers (16:32) */ +typedef long long intptr_t; +typedef unsigned long long uintptr_t; +# endif + +#endif + +/* stdarg.h */ +#include <../h/stdarg.h> + +#endif /* !IPRT_INCLUDED_nocrt_compiler_watcom_h */ + diff --git a/include/iprt/nocrt/cstddef b/include/iprt/nocrt/cstddef new file mode 100644 index 00000000..2b3c29e9 --- /dev/null +++ b/include/iprt/nocrt/cstddef @@ -0,0 +1,52 @@ +/** @file + * IPRT / No-CRT - Dummy cstddef. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_cstddef +#define VBOX_INCLUDED_SRC_nocrt_cstddef +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/sys/types.h> + +namespace std +{ + using size_t = ::size_t; + using ptrdiff_t = ::ptrdiff_t; +} + + +#endif /* !VBOX_INCLUDED_SRC_nocrt_cstddef */ + diff --git a/include/iprt/nocrt/cstdlib b/include/iprt/nocrt/cstdlib new file mode 100644 index 00000000..2a11d98f --- /dev/null +++ b/include/iprt/nocrt/cstdlib @@ -0,0 +1,47 @@ +/** @file + * IPRT / No-CRT - Dummy cstdlib. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_cstdlib +#define VBOX_INCLUDED_SRC_nocrt_cstdlib +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/stdlib.h> +#include <iprt/nocrt/cstddef> + + +#endif /* !VBOX_INCLUDED_SRC_nocrt_cstdlib */ + diff --git a/include/iprt/nocrt/ctype.h b/include/iprt/nocrt/ctype.h new file mode 100644 index 00000000..466a9283 --- /dev/null +++ b/include/iprt/nocrt/ctype.h @@ -0,0 +1,61 @@ +/** @file + * IPRT / No-CRT - Our own minimal ctype.h header (needed by ntdefs.h). + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_ctype_h +#define IPRT_INCLUDED_nocrt_ctype_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/ctype.h> + +#define isspace(a_ch) RT_C_IS_SPACE(a_ch) +#define isblank(a_ch) RT_C_IS_BLANK(a_ch) +#define isdigit(a_ch) RT_C_IS_DIGIT(a_ch) +#define isxdigit(a_ch) RT_C_IS_XDIGIT(a_ch) +#define isalpha(a_ch) RT_C_IS_ALPHA(a_ch) +#define isalnum(a_ch) RT_C_IS_ALNUM(a_ch) +#define iscntrl(a_ch) RT_C_IS_CNTRL(a_ch) +#define isgraph(a_ch) RT_C_IS_GRAPH(a_ch) +#define ispunct(a_ch) RT_C_IS_PUNCT(a_ch) +#define isprint(a_ch) RT_C_IS_PRINT(a_ch) +#define isupper(a_ch) RT_C_IS_UPPER(a_ch) +#define islower(a_ch) RT_C_IS_LOWER(a_ch) + +#define tolower(a_ch) RT_C_TO_LOWER(a_ch) +#define toupper(a_ch) RT_C_TO_UPPER(a_ch) + +#endif /* !IPRT_INCLUDED_nocrt_ctype_h */ + diff --git a/include/iprt/nocrt/direct.h b/include/iprt/nocrt/direct.h new file mode 100644 index 00000000..72f23a17 --- /dev/null +++ b/include/iprt/nocrt/direct.h @@ -0,0 +1,43 @@ +/** @file + * IPRT / No-CRT - Stub direct.h header (for MSC compatibility). + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_direct_h +#define IPRT_INCLUDED_nocrt_direct_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#endif /* !IPRT_INCLUDED_nocrt_direct_h */ + diff --git a/include/iprt/nocrt/errno.h b/include/iprt/nocrt/errno.h new file mode 100644 index 00000000..1217a531 --- /dev/null +++ b/include/iprt/nocrt/errno.h @@ -0,0 +1,56 @@ +/** @file + * IPRT / No-CRT - Dummy errno.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_errno_h +#define IPRT_INCLUDED_nocrt_errno_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +# include <iprt/errno.h> + +RT_C_DECLS_BEGIN + +RTDECL(int *) rtNoCrtGetErrnoPtr(void); +# define errno (*rtNoCrtGetErrnoPtr()) + +RT_C_DECLS_END + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + +#endif /* !IPRT_INCLUDED_nocrt_errno_h */ + diff --git a/include/iprt/nocrt/exception b/include/iprt/nocrt/exception new file mode 100644 index 00000000..6e6ee777 --- /dev/null +++ b/include/iprt/nocrt/exception @@ -0,0 +1,90 @@ +/** @file + * IPRT / No-CRT - Our own exception header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_exception +#define VBOX_INCLUDED_SRC_nocrt_exception +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +namespace std { + +/** Exception base class. */ +class exception +{ +public: + exception() RT_NOEXCEPT +#ifdef _MSC_VER + : m_pszWhat(NULL) +#endif + { } + + exception(const exception &a_rThat) RT_NOEXCEPT +#ifdef _MSC_VER + : m_pszWhat(a_rThat.m_pszWhat) +#endif + { + RT_NOREF(a_rThat); + } + +#ifdef _MSC_VER + exception(const char *a_pszWhat, int a_iIgnored = 0) RT_NOEXCEPT + : m_pszWhat(a_pszWhat) + { RT_NOREF(a_iIgnored); } +#endif + + virtual ~exception() RT_NOEXCEPT + {} + + virtual const char *what() const RT_NOEXCEPT + { +#ifdef _MSC_VER + if (m_pszWhat) + return m_pszWhat; +#endif + return "unknown exception"; + } +#ifdef _MSC_VER +protected: + const char *m_pszWhat; +#endif +}; + +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_exception */ + diff --git a/include/iprt/nocrt/fcntl.h b/include/iprt/nocrt/fcntl.h new file mode 100644 index 00000000..49cf6f4b --- /dev/null +++ b/include/iprt/nocrt/fcntl.h @@ -0,0 +1,90 @@ +/** @file + * IPRT / No-CRT - fcntl.h + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_fcntl_h +#define IPRT_INCLUDED_nocrt_fcntl_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/time.h> /* to establish the timespec and timeval types before iprt/file.h includes iprt/time.h */ +#include <iprt/file.h> + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY + +/* Open flags:*/ +AssertCompile(RT_IS_POWER_OF_TWO(RTFILE_O_OPEN_CREATE)); +AssertCompile(RT_IS_POWER_OF_TWO(RTFILE_O_CREATE)); +# define _O_CREAT RTFILE_O_OPEN_CREATE +# define _O_EXCL RTFILE_O_CREATE /**< Will remove RTFILE_O_OPEN_CREATE when processing it. */ +# define _O_TRUNC RTFILE_O_TRUNCATE +# define _O_APPEND RTFILE_O_APPEND +# define _O_RDONLY RTFILE_O_READ +# define _O_WRONLY RTFILE_O_WRITE +# define _O_RDWR (RTFILE_O_READ | RTFILE_O_WRITE) +# define _O_CLOEXEC RTFILE_O_INHERIT /**< Invert meaning when processing it. */ +# define _O_NOINHERIT O_CLOEXEC +# define _O_LARGEFILE 0 +# define _O_BINARY 0 + +# define O_CREAT _O_CREAT +# define O_EXCL _O_EXCL +# define O_TRUNC _O_TRUNC +# define O_APPEND _O_APPEND +# define O_RDONLY _O_RDONLY +# define O_WRONLY _O_WRONLY +# define O_RDWR _O_RDWR +# define O_CLOEXEC _O_CLOEXEC +# define O_NOINHERIT _O_NOINHERIT +# define O_BINARY _O_BINARY + +RT_C_DECLS_BEGIN + +int RT_NOCRT(open)(const char *pszFilename, uint64_t fFlags, ... /*RTFMODE fMode*/); +int RT_NOCRT(_open)(const char *pszFilename, uint64_t fFlags, ... /*RTFMODE fMode*/); + +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define open RT_NOCRT(open) +# define _open RT_NOCRT(_open) +# endif + +RT_C_DECLS_END + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + + + +#endif /* !IPRT_INCLUDED_nocrt_fcntl_h */ + diff --git a/include/iprt/nocrt/fenv.h b/include/iprt/nocrt/fenv.h new file mode 100644 index 00000000..7af59d13 --- /dev/null +++ b/include/iprt/nocrt/fenv.h @@ -0,0 +1,49 @@ +/** @file + * IPRT / No-CRT - fenv.h wrapper. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_fenv_h +#define IPRT_INCLUDED_nocrt_fenv_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/cdefs.h> +#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) +# include <iprt/nocrt/x86/fenv-x86-amd64.h> +#else +# error "IPRT: no fenv.h available for this platform, or the platform define is missing!" +#endif + +#endif /* !IPRT_INCLUDED_nocrt_fenv_h */ diff --git a/include/iprt/nocrt/float.h b/include/iprt/nocrt/float.h new file mode 100644 index 00000000..f0e8081d --- /dev/null +++ b/include/iprt/nocrt/float.h @@ -0,0 +1,131 @@ +/** @file + * IPRT / No-CRT - Our minimal float.h. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_float_h +#define IPRT_INCLUDED_nocrt_float_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +/* + * Common. + */ +#define FLT_RADIX 2 + + +/* + * float + */ +#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) + +# define FLT_MAX (3.40282347E+38F) +# define FLT_MIN (1.17549435E-38F) +# define FLT_TRUE_MIN (1.40129846E-45F) +# define FLT_MAX_EXP (128) +# define FLT_MIN_EXP (-125) +# define FLT_MAX_10_EXP (38) +# define FLT_MIN_10_EXP (-37) +# define FLT_EPSILON (1.192092896E-07F) +# define FLT_DIG (6) +# define FLT_DECIMAL_DIG (9) +# define FLT_MANT_DIG (24) +# define FLT_HAS_SUBNORM (1) + +#endif + +/* + * double + */ +#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) + +# ifdef _MSC_VER +# define DBL_MAX (1.7976931348623158E+308) +# else +# define DBL_MAX (1.7976931348623157E+308) +# endif +# define DBL_MIN (2.2250738585072014E-308) +# define DBL_TRUE_MIN (4.9406564584124654E-324) +# define DBL_MAX_EXP (1024) +# define DBL_MIN_EXP (-1021) +# define DBL_MAX_10_EXP (308) +# define DBL_MIN_10_EXP (-307) +# define DBL_EPSILON (2.2204460492503131E-16) +# define DBL_DIG (15) +# define DBL_DECIMAL_DIG (17) +# define DBL_MANT_DIG (53) +# define DBL_HAS_SUBNORM (1) + +#endif + +/* + * long double + */ +#if ((defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(RT_OS_WINDOWS)) || defined(RT_ARCH_ARM64) /*?*/ + +# define LDBL_MAX DBL_MAX +# define LDBL_MIN DBL_MIN +# define LDBL_TRUE_MIN DBL_TRUE_MIN +# define LDBL_MAX_EXP DBL_MAX_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# define LDBL_MAX_10_EXP DBL_MAX_10_EXP +# define LDBL_MIN_10_EXP DBL_MIN_10_EXP +# define LDBL_EPSILON DBL_EPSILON +# define LDBL_DIG DBL_DIG +# define LDBL_DECIMAL_DIG DBL_DECIMAL_DIG +# define LDBL_MANT_DIG DBL_MANT_DIG +# define LDBL_HAS_SUBNORM DBL_HAS_SUBNORM + +#elif defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) + +# define LDBL_MAX (1.1897314953572317650E+4932L) +# define LDBL_MIN (3.3621031431120935063E-4932L) +# define LDBL_TRUE_MIN (3.6451995318824746025E-4951L) +# define LDBL_MAX_EXP (-16381) +# define LDBL_MIN_EXP (16384) +# define LDBL_MAX_10_EXP (4932) +# define LDBL_MIN_10_EXP (-4931) +# define LDBL_EPSILON (1.0842021724855044340E-19L) +# define LDBL_DIG (18) +# define LDBL_DECIMAL_DIG (21) +# define LDBL_MANT_DIG (64) +# define LDBL_HAS_SUBNORM (1) + +#endif + + +#endif /* !IPRT_INCLUDED_nocrt_float_h */ + diff --git a/include/iprt/nocrt/fstream b/include/iprt/nocrt/fstream new file mode 100644 index 00000000..1abd06eb --- /dev/null +++ b/include/iprt/nocrt/fstream @@ -0,0 +1,206 @@ +/** @file + * IPRT / No-CRT - Minimal C++ fstream header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_fstream +#define VBOX_INCLUDED_SRC_nocrt_fstream +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/ostream> +#include <iprt/stream.h> + + +namespace std +{ + template<typename a_CharType, typename a_CharTraits /*= std::char_traits<a_CharType>*/ > + class basic_filebuf : public basic_streambuf<a_CharType, a_CharTraits> + { + protected: + PRTSTREAM m_pStrm; + bool m_fStdStream; + ios_base::openmode m_fMode; + + public: + basic_filebuf(PRTSTREAM a_pStrm = NULL, bool a_fStdStream = false) + : basic_streambuf() + , m_pStrm(a_pStrm) + , m_fStdStream(a_fStdStream) + , m_fMode(ios_base::openmode(0)) + { + } + + virtual ~basic_filebuf() + { + if (m_pStrm) + { + if (m_fStdStream) + RTStrmClose(m_pStrm); + m_pStrm = NULL; + } + } + + bool is_open() const RT_NOEXCEPT + { + return m_pStrm != NULL; + } + + basic_filebuf *open(const char *a_pszFilename, ios_base::openmode a_fMode) + { + /* + * Sanitize the a_fMode first. + */ + AssertReturn(!is_open(), NULL); + AssertReturn(a_fMode & (ios_base::out | ios_base::in), NULL); /* Neither write nor read mode? */ + AssertStmt((a_fMode & (ios_base::out | ios_base::app)) != ios_base::app, a_fMode &= ~ios_base::app); + AssertReturn((a_fMode & (ios_base::out | ios_base::trunc)) != ios_base::trunc, NULL); + AssertReturn(!(a_fMode & ios_base::trunc) || !(a_fMode & ios_base::app), NULL); + + /* + * Translate a_fMode into a stream mode string and try open the file. + */ + char szMode[8]; + szMode[0] = a_fMode & ios_base::trunc ? 'w' : a_fMode & ios_base::app ? 'a' : 'r'; + size_t offMode = 1; + if ((a_fMode & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)) + szMode[offMode++] = '+'; + if (a_fMode & ios_base::binary) + szMode[offMode++] = 'b'; + szMode[offMode] = '\0'; + + int rc = RTStrmOpen(a_pszFilename, szMode, &m_pStrm); + if (RT_SUCCESS(rc)) + { + /** @todo if (a_fMode & ios_base::ate)? */ + + /* + * Set up the buffer? + */ + if (true) + { + return this; + } + + RTStrmClose(m_pStrm); + m_pStrm = NULL; + } + return NULL; + } + + protected: + bool flushBuffered() + { + /** @todo buffering. */ + return true; + } + + //virtual int_type overflow(int_type a_iChar) RT_OVERRIDE + //{ + // if (a_iChar != traits_type::eof()) + // { + // if (flushBuffered()) + // { + // char_type ch = traits_type::to_char_type(a_iChar); + // int rc = RTStrmWrite(m_pStrm, &ch, sizeof(ch)); + // if (RT_SUCCESS(rc)) + // return a_iChar; + // } + // } + // return traits_type::eof(); + //} + + std::streamsize xsputn(char_type const *a_pchSrc, std::streamsize a_cchSrc) //RT_OVERRIDE + { + if (flushBuffered()) + { + size_t cbWritten = 0; + int rc = RTStrmWriteEx(m_pStrm, &a_pchSrc, sizeof(a_pchSrc[0]) * a_cchSrc, &cbWritten); + if (RT_SUCCESS(rc)) + return cbWritten / sizeof(a_pchSrc[0]); + } + return 0; + } + }; + + + /** + * Basic I/O stream. + */ + template<typename a_CharType, typename a_CharTraits /*= std::char_traits<a_CharType>*/ > + class basic_ofstream : public basic_ostream<a_CharType, a_CharTraits> + { + protected: + basic_filebuf<a_CharType, a_CharTraits> m_FileBuf; + + public: + basic_ofstream() + : basic_ostream(&m_FileBuf) /** @todo m_FileBuf isn't initialized yet... */ + , m_FileBuf() + { + } + + explicit basic_ofstream(const char *a_pszFilename, ios_base::openmode a_fMode = ios_base::out) + : basic_ostream(&m_FileBuf) /** @todo m_FileBuf isn't initialized yet... */ + , m_FileBuf() + { + m_FileBuf.open(a_pszFilename, a_fMode); + } + private: + basic_ofstream(basic_ofstream const &a_rSrc); /* no copying */ + basic_ofstream &operator=(basic_ofstream const &a_rSrc); /* no copying */ + + public: + virtual ~basic_ofstream() + { + } + + public: + + bool is_open() const RT_NOEXCEPT + { + return m_FileBuf.is_open(); + } + + basic_filebuf<a_CharType, a_CharTraits> *open(const char *a_pszFilename, ios_base::openmode a_fMode) + { + return m_FileBuf.open(a_pszFilename, a_fMode); + } + + + }; +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_fstream */ + diff --git a/include/iprt/nocrt/inttypes.h b/include/iprt/nocrt/inttypes.h new file mode 100644 index 00000000..cb2265c8 --- /dev/null +++ b/include/iprt/nocrt/inttypes.h @@ -0,0 +1,75 @@ +/** @file + * IPRT / No-CRT - Our minimal inttypes.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_inttypes_h +#define IPRT_INCLUDED_nocrt_inttypes_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +#define PRId8 "RI8" +#define PRIi8 "RI8" +#define PRIx8 "RX8" +#define PRIu8 "RU8" +#define PRIo8 huh? anyone using this? great! + +#define PRId16 "RI16" +#define PRIi16 "RI16" +#define PRIx16 "RX16" +#define PRIu16 "RU16" +#define PRIo16 huh? anyone using this? great! + +#define PRId32 "RI32" +#define PRIi32 "RI32" +#define PRIx32 "RX32" +#define PRIu32 "RU32" +#define PRIo32 huh? anyone using this? great! + +#define PRId64 "RI64" +#define PRIi64 "RI64" +#define PRIx64 "RX64" +#define PRIu64 "RU64" +#define PRIo64 huh? anyone using this? great! + +#define PRIdMAX "RI64" +#define PRIiMAX "RI64" +#define PRIxMAX "RX64" +#define PRIuMAX "RU64" +#define PRIoMAX huh? anyone using this? great! + +#endif /* !IPRT_INCLUDED_nocrt_inttypes_h */ + diff --git a/include/iprt/nocrt/io.h b/include/iprt/nocrt/io.h new file mode 100644 index 00000000..f8d42941 --- /dev/null +++ b/include/iprt/nocrt/io.h @@ -0,0 +1,48 @@ +/** @file + * IPRT / No-CRT - io.h (DOS, OS/2, Windows compilers). + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_io_h +#define IPRT_INCLUDED_nocrt_io_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/fcntl.h> +#include <iprt/nocrt/sys/stat.h> +#include <iprt/nocrt/unistd.h> + + +#endif /* !IPRT_INCLUDED_nocrt_io_h */ + diff --git a/include/iprt/nocrt/iomanip b/include/iprt/nocrt/iomanip new file mode 100644 index 00000000..29c651e9 --- /dev/null +++ b/include/iprt/nocrt/iomanip @@ -0,0 +1,166 @@ +/** @file + * IPRT / No-CRT - Minimal C++ iomanip header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_iomanip +#define VBOX_INCLUDED_SRC_nocrt_iomanip +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/ios> + + +namespace std +{ + /** + * Used by all flag manipulators. + */ + struct rtNoCrtIosSetFlagsEx + { + ios_base::fmtflags m_fSet; + ios_base::fmtflags m_fMask; + }; + + template<typename a_CharType, typename a_CharTraits> + inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc, + struct rtNoCrtIosSetFlagsEx a_Change) + { + a_rSrc.setf(a_Change.m_fSet, a_Change.m_fMask); + return a_rSrc; + } + + template<typename a_CharType, typename a_CharTraits> + inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, + struct rtNoCrtIosSetFlagsEx a_Change) + { + a_rDst.setf(a_Change.m_fSet, a_Change.m_fMask); + return a_rDst; + } + + + /* + * Flag modification functions. + */ + + inline struct rtNoCrtIosSetFlagsEx setiosflags(ios_base::fmtflags a_fFlags) + { + struct rtNoCrtIosSetFlagsEx Ret = { a_fFlags, a_fFlags }; + return Ret; + } + + inline struct rtNoCrtIosSetFlagsEx resetiosflags(ios_base::fmtflags a_fFlags) + { + struct rtNoCrtIosSetFlagsEx Ret = { ios_base::fmtflags(0), a_fFlags }; + return Ret; + } + + inline struct rtNoCrtIosSetFlagsEx setbase(int a_iBase) + { + struct rtNoCrtIosSetFlagsEx Ret = + { + a_iBase == 10 ? ios_base::dec + : a_iBase == 16 ? ios_base::hex + : a_iBase == 8 ? ios_base::oct + : ios_base::fmtflags(0), + ios_base::basefield + }; + return Ret; + } + + /* + * Modify precision. + */ + struct rtNoCrtIosSetPrecision + { + int m_cchPrecision; + }; + + template<typename a_CharType, typename a_CharTraits> + inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc, + struct rtNoCrtIosSetPrecision a_Change) + { + a_rSrc.precision(a_Change.m_cchPrecision); + return a_rSrc; + } + + template<typename a_CharType, typename a_CharTraits> + inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, + struct rtNoCrtIosSetPrecision a_Change) + { + a_rDst.precision(a_Change.m_cchPrecision); + return a_rDst; + } + + inline struct rtNoCrtIosSetPrecision setprecision(int a_cchPrecision) + { + struct rtNoCrtIosSetPrecision Ret = { a_cchPrecision }; + return Ret; + } + + /* + * Modify width. + */ + struct rtNoCrtIosSetWidth + { + int m_cchWidth; + }; + + template<typename a_CharType, typename a_CharTraits> + inline basic_istream<a_CharType, a_CharTraits> &operator>>(basic_istream<a_CharType, a_CharTraits> &a_rSrc, + struct rtNoCrtIosSetWidth a_Change) + { + a_rSrc.width(a_Change.m_cchWidth); + return a_rSrc; + } + + template<typename a_CharType, typename a_CharTraits> + inline basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, + struct rtNoCrtIosSetWidth a_Change) + { + a_rDst.width(a_Change.m_cchWidth); + return a_rDst; + } + + inline struct rtNoCrtIosSetWidth setw(int a_cchWidth) + { + struct rtNoCrtIosSetWidth Ret = { a_cchWidth }; + return Ret; + } + + /** @todo setfil, get_money, set_money, get_time, set_time */ +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_iomanip */ + diff --git a/include/iprt/nocrt/ios b/include/iprt/nocrt/ios new file mode 100644 index 00000000..9e49eaa9 --- /dev/null +++ b/include/iprt/nocrt/ios @@ -0,0 +1,525 @@ +/** @file + * IPRT / No-CRT - Minimal C++ ios header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_ios +#define VBOX_INCLUDED_SRC_nocrt_ios +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/iosfwd> +#include <iprt/nocrt/string> + +/** @todo something for cdecl.h */ +#define RTNOCRT_IOS_ENUM_BIT_OPS(a_EnumType, a_IntType) \ + inline a_EnumType operator~(a_EnumType a_fLeft) RT_NOEXCEPT \ + { return a_EnumType(~static_cast<a_IntType>(a_fLeft)); } \ + \ + inline a_EnumType operator&(a_EnumType a_fLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_EnumType(static_cast<a_IntType>(a_fLeft) & static_cast<a_IntType>(a_fRight)); } \ + inline a_EnumType operator|(a_EnumType a_fLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_EnumType(static_cast<a_IntType>(a_fLeft) | static_cast<a_IntType>(a_fRight)); } \ + inline a_EnumType operator^(a_EnumType a_fLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_EnumType(static_cast<a_IntType>(a_fLeft) ^ static_cast<a_IntType>(a_fRight)); } \ + \ + inline const a_EnumType &operator&=(a_EnumType &a_rfLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_rfLeft = a_rfLeft & a_fRight; } \ + inline const a_EnumType &operator|=(a_EnumType &a_rfLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_rfLeft = a_rfLeft | a_fRight; } \ + inline const a_EnumType &operator^=(a_EnumType &a_rfLeft, a_EnumType a_fRight) RT_NOEXCEPT \ + { return a_rfLeft = a_rfLeft ^ a_fRight; } \ + +namespace std +{ + typedef ptrdiff_t streamsize; + + /** + * I/O stream format flags. + */ + class rtNoCrtIosEnums + { + public: + enum fmtflags + { + /* int: */ + dec = 0x00000001, + oct = 0x00000002, + hex = 0x00000004, + basefield = 0x00000007, + /* float: */ + scientific = 0x00000010, + fixed = 0x00000020, + floatfield = 0x00000030, + /* int and float output tweaks: */ + showbase = 0x00000100, + showpoint = 0x00000200, + showpos = 0x00000400, + /* bool: */ + boolalpha = 0x00000800, + /* adjustment: */ + left = 0x00001000, + right = 0x00002000, + internal = 0x00004000, + adjustfield = 0x00007000, + /* misc: */ + skipws = 0x00010000, + unitbuf = 0x00020000, + uppercase = 0x00040000, + }; + + enum seekdir + { + beg = 1, + end, + cur, + }; + + enum openmode + { + app = 1, + binary, + in, + out, + trunc, + ate + }; + + enum iostate + { + goodbit = 0, + badbit = 1, + failbit = 2, + eofbit = 4 + }; + }; + RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::fmtflags, int) + RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::seekdir, int) + RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::openmode, int) + RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::iostate, int) + + + /** + * I/O stream base class. + */ + class ios_base : public rtNoCrtIosEnums + { + public: + //typedef rtNoCrtIosFmtFlags fmtflags; + //typedef rtNoCrtIosSeekDir seekdir; + //typedef rtNoCrtIosOpenMode openmode; + //typedef rtNoCrtIosState iostate; + + protected: + streamsize m_cWidth; + streamsize m_cPrecision; + fmtflags m_fFlags; + iostate m_fState; + + protected: + ios_base() + : m_cWidth(0) + , m_cPrecision(0) + , m_fFlags(dec | skipws) + , m_fState(goodbit) + { + } + private: + ios_base(const ios_base &); /* not copyable */ + ios_base &operator=(const ios_base &); /* not copyable */ + + public: + virtual ~ios_base() + { + } + + streamsize width() const RT_NOEXCEPT + { + return m_cWidth; + } + + streamsize width(streamsize a_cWidth) RT_NOEXCEPT + { + streamsize cOldWidth = m_cWidth; + m_cWidth = a_cWidth; + return cOldWidth; + } + + streamsize precision() const RT_NOEXCEPT + { + return m_cPrecision; + } + + streamsize precision(streamsize a_cPrecision) RT_NOEXCEPT + { + streamsize cOldPrecision = m_cPrecision; + m_cPrecision = a_cPrecision; + return cOldPrecision; + } + + fmtflags flags() const RT_NOEXCEPT + { + return m_fFlags; + } + + fmtflags flags(fmtflags a_fNew) RT_NOEXCEPT + { + fmtflags const fOld = m_fFlags; + m_fFlags = a_fNew; + return fOld; + } + + fmtflags setf(fmtflags a_fAdd) RT_NOEXCEPT + { + fmtflags const fOld = m_fFlags; + m_fFlags = static_cast<fmtflags>(fOld | a_fAdd); + return fOld; + } + + fmtflags setf(fmtflags a_fAdd, fmtflags a_fMask) RT_NOEXCEPT + { + fmtflags const fOld = m_fFlags; + m_fFlags = static_cast<fmtflags>((fOld & ~a_fMask) | (a_fAdd & a_fMask)); + return fOld; + } + + void unsetf(fmtflags a_fClear) RT_NOEXCEPT + { + m_fFlags = static_cast<fmtflags>(m_fFlags & ~a_fClear); + } + }; + + + /** + * Stream buffer. + */ + template<typename a_CharType, typename a_CharTraits /*= std::char_traits<a_CharType>*/ > + class basic_streambuf + { + public: + typedef a_CharType char_type; + typedef a_CharTraits traits_type; + typedef typename a_CharTraits::int_type int_type; + typedef typename a_CharTraits::pos_type pos_type; + typedef typename a_CharTraits::off_type off_type; + + protected: + /** @name Put buffering + * @{ */ + char_type *m_pachPut; /**< The put buffer pointer. */ + std::size_t m_cchPut; /**< Put buffer size. */ + std::size_t m_offPutNext; /**< The current put buffer position (where to write next). */ + std::size_t m_offPutStart; /**< Where the buffered put sequence starts. */ + + void setp(char_type *a_pachNewBuf, char_type *a_pachNewBufEnd) + { + Assert((uintptr_t)a_pachNewBuf <= (uintptr_t)a_pachNewBufEnd); + m_pachPut = a_pachNewBuf; + m_cchPut = static_cast<std::size_t>(a_pachNewBufEnd - a_pachNewBuf); + m_offPutNext = 0; + m_offPutStart = 0; + } + + char_type *pbbase() const RT_NOEXCEPT + { + Assert(m_offPutNext >= m_offPutStart); Assert(m_offPutNext <= m_cchPut); Assert(m_offPutStart <= m_cchPut); + return &m_pachPut[m_offPutStart]; + } + + char_type *pptr() const RT_NOEXCEPT + { + Assert(m_offPutNext <= m_cchPut); + return &m_pachPut[m_offPutNext]; + } + + char_type *epptr() const RT_NOEXCEPT + { + return &m_pachBuf[m_cchPut]; + } + + void pbump(int a_cchAdvance) const RT_NOEXCEPT + { + Assert(m_offPutNext <= m_cchPut); + m_offPutNext += a_cchAdvance; + Assert(m_offPutNext <= m_cchPut); + } + /** @} */ + + protected: + basic_streambuf() RT_NOEXCEPT + : m_pachPut(NULL) + , m_cchPut(0) + , m_offPutNext(0) + , m_offPutStart(0) + { + } + + basic_streambuf(const basic_streambuf &a_rSrc) RT_NOEXCEPT + : m_pachPut(a_rSrc.m_pachPut) + , m_cchPut(a_rSrc.m_cchPut) + , m_offPutNext(a_rSrc.m_offPutNext) + , m_offPutStart(a_rSrc.m_offPutStart) + { + } + + public: + virtual ~basic_streambuf() + { + } + + /** @name Positioning + * @{ */ + protected: + virtual basic_streambuf *setbuf(char_type *a_pchBuf, std::streamsize a_cchBuf) + { + RT_NOREF(a_pchBuf, a_cchBuf); + return this; + } + public: + basic_streambuf *pubsetbuf(char_type *a_pchBuf, std::streamsize a_cchBuf) + { + return setbuf(a_pchBuf, a_cchBuf); + } + + protected: + virtual pos_type seekoff(off_type a_off, std::ios_base::seekdir a_enmDir, + std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) + { + RT_NOREF(a_off, a_enmDir, a_enmTarget); + return pos_type(off_type(-1)); + } + public: + pos_type pubseekoff(off_type a_off, std::ios_base::seekdir a_enmDir, + std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) + { + return seekoff(a_off, a_enmDir, a_enmTarget); + } + + protected: + virtual pos_type seekpos(pos_type a_pos, std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) + { + RT_NOREF(a_pos, a_enmTarget); + return pos_type(off_type(-1)); + } + public: + pos_type pubseekpos(pos_type a_pos, std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) + { + return seekpos(a_pos, a_enmTarget); + } + + protected: + virtual int sync() + { + return 0; + } + public: + pos_type pubsync() + { + return sync(); + } + /** @} */ + + /** @name Output + * @{ */ + protected: + virtual int_type overflow(int_type a_iChar) + { + RT_NOREF(a_iChar); + return traits_type::eof(); + } + + virtual std::streamsize xsputn(char_type const *a_pchSrc, std::streamsize a_cchSrc) + { + std::streamsize cchWritten = 0; + while (a_cchSrc > 0) + { + std::size_t cchCopied = m_cchPut - m_offPutNext; + if (cchCopied > 0) + { + cchCopied = RT_MIN(cchCopied, static_cast<std::size_t>(a_cchSrc)); + traits_type::copy(&m_pachPut[m_offPutNext], a_pchSrc, cchCopied); + m_cchPut += cchCopied; + } + else + { + if (overflow(traits_type::to_int_type(m_pachPut[m_offPutNext])) != traits_type::eof()) + cchCopied = 1; + else + break; + } + a_pchSrc += cchCopied; + a_cchSrc -= cchCopied; + } + return cchWritten; + } + + public: + int_type sputc(char_type a_ch) + { + if (m_offPutNext < m_cchPut) + { + m_pachPut[m_offPutNext++] = a_ch; + return traits_type::to_int_type(a_ch); + } + return overflow(traits_type::to_int_type(a_ch)); + } + + std::streamsize sputn(char_type const *a_pchSrc, std::streamsize a_cchSrc) + { + AssertReturn(a_cchSrc >= 0, 0); + return xsputn(a_pchSrc, a_cchSrc); + } + + /** @} */ + + /** @todo add the remaining members... */ + }; + + + /** + * Basic I/O stream. + */ + template<typename a_CharType, typename a_CharTraits /*= std::char_traits<a_CharType>*/ > + class basic_ios : public ios_base + { + public: + typedef a_CharType char_type; + typedef a_CharTraits traits_type; + typedef typename a_CharTraits::int_type int_type; + typedef typename a_CharTraits::pos_type pos_type; + typedef typename a_CharTraits::off_type off_type; + + protected: + basic_streambuf<a_CharType, a_CharTraits> *m_pBuf; + basic_ostream<a_CharType, a_CharTraits> *m_pTiedStream; + + protected: + void init(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) + { + m_pBuf = a_pBuf; + m_cWidth = 0; + m_cPrecision = 6; + m_fFlags = ios_base::dec | ios_base::skipws; + m_fState = ios_base::goodbit; + } + + public: + basic_ios() + : ios_base() + , m_pBuf(NULL) + , m_pTiedStream(NULL) + { + } + + basic_ios(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) + : ios_base() + , m_pBuf(NULL) + , m_pTiedStream(NULL) + { + init(a_pBuf); + } + private: + basic_ios(const basic_ios &a_rSrc); /* not copyable */ + basic_ios &operator=(const basic_ios &a_rSrc); /* not copyable */ + + public: + virtual ~basic_ios() + { + } + + /** @name State methods + * @{ */ + bool good() const RT_NOEXCEPT { return m_fState == ios_base::goodbit; } + bool fail() const RT_NOEXCEPT { return (m_fState & (ios_base::failbit | ios_base::badbit)) != ios_base::goodbit; } + bool bad() const RT_NOEXCEPT { return (m_fState & ios_base::badbit) == ios_base::badbit; } + bool eof() const RT_NOEXCEPT { return (m_fState & ios_base::eofbit) != ios_base::eofbit; } +#if RT_CPLUSPLUS_PREREQ(201100) + operator bool() const RT_NOEXCEPT { return good(); } +#else + operator void*() const RT_NOEXCEPT { return good() ? NULL : this; } +#endif + bool operator!() const RT_NOEXCEPT { return fail(); } + + iostate rdstate() const RT_NOEXCEPT + { + return m_fState; + } + + void clear(iostate a_fNewState = goodbit) + { + m_fState = a_fNewState; + if (!m_pBuf) + m_fState |= badbit; + /** @todo failure exception */ + } + + void setstate(iostate a_fNewState) + { + clear(m_fState | a_fNewState); + } + /** @} */ + + /** @name Misc + * @{ */ + std::basic_streambuf<a_CharType, a_CharTraits> *rdbuf() const RT_NOEXCEPT + { + return m_pBuf; + } + + std::basic_streambuf<a_CharType, a_CharTraits> *rdbuf(std::basic_streambuf<a_CharType, a_CharTraits> *a_pNewbuf) RT_NOEXCEPT + { + std::basic_streambuf<a_CharType, a_CharTraits> *pOldBuf = m_pBuf; + m_pBuf = a_pNewBuf; + return pOldBuf; + } + + std::basic_ostream<a_CharType, a_CharTraits> *tie() const + { + return m_pTiedStream; + } + + std::basic_ostream<a_CharType, a_CharTraits> tie(std::basic_ostream<a_CharType, a_CharTraits> *a_pNew) const RT_NOEXCEPT + { + std::basic_ostream<a_CharType, a_CharTraits> * const pOld = m_pTiedStream; + m_pTiedStream = a_pNew; + return pOld; + } + /** @} */ + + /** @todo implement the rest... */ + }; +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_ios */ + diff --git a/include/iprt/nocrt/iosfwd b/include/iprt/nocrt/iosfwd new file mode 100644 index 00000000..835f4a5e --- /dev/null +++ b/include/iprt/nocrt/iosfwd @@ -0,0 +1,81 @@ +/** @file + * IPRT / No-CRT - Minimal C++ iosfwd header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_iosfwd +#define VBOX_INCLUDED_SRC_nocrt_iosfwd +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/memory> +#include <iprt/nocrt/string> + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4643) /* warning C4643: Forward declaring 'ios_base' in namespace std is not permitted by the C++ Standard */ +#endif + +namespace std +{ + using streamoff = RTFOFF; + + class ios_base; + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ios; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_streambuf; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_istream; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ostream; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_iostream; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ifstream; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ofstream; + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_fstream; + + + typedef basic_ios<char> ios; + typedef basic_streambuf<char> streambuf; + typedef basic_istream<char> istream; + typedef basic_ostream<char> ostream; + typedef basic_iostream<char> iostream; + typedef basic_ifstream<char> ifstream; + typedef basic_ofstream<char> ofstream; + typedef basic_fstream<char> fstream; +} + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +#endif /* !VBOX_INCLUDED_SRC_nocrt_iosfwd */ + diff --git a/include/iprt/nocrt/iostream b/include/iprt/nocrt/iostream new file mode 100644 index 00000000..d4997a99 --- /dev/null +++ b/include/iprt/nocrt/iostream @@ -0,0 +1,53 @@ +/** @file + * IPRT / No-CRT - Minimal C++ iostream header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_iostream +#define VBOX_INCLUDED_SRC_nocrt_iostream +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/iosfwd> + +namespace std +{ + extern istream cin; + extern ostream cout; + extern ostream cerr; + extern ostream clog; /**< buffered cerr */ +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_iostream */ + diff --git a/include/iprt/nocrt/limits b/include/iprt/nocrt/limits new file mode 100644 index 00000000..0d414536 --- /dev/null +++ b/include/iprt/nocrt/limits @@ -0,0 +1,494 @@ +/** @file + * IPRT / No-CRT - C++ limits header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_limits +#define VBOX_INCLUDED_SRC_nocrt_limits +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/limits.h> +#include <iprt/nocrt/float.h> + +namespace std +{ + enum float_denorm_style + { + denorm_indeterminate = -1, + denorm_absent, + denorm_present, + }; + + enum float_round_style + { + round_indeterminate = -1, + round_toward_zero, + round_to_nearest, + round_toward_infinity, + round_toward_neg_infinity, + }; + + struct rtNoCrtLimitNumericBase + { + static const bool is_specialized = false; + static const bool is_integer = false; + static const bool is_signed = false; + static const bool is_exact = false; + static const bool is_bounded = false; + + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool has_denorm_loss = false; + static const bool is_iec559 = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const int radix = 0; + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + + static const float_denorm_style has_denorm = denorm_absent; + static const float_round_style round_style = round_toward_zero; + }; + + struct rtNoCrtLimitNumericIntBase : public rtNoCrtLimitNumericBase + { + static const bool is_specialized = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool is_bounded = true; + static const int radix = 2; + }; + + struct rtNoCrtLimitNumericFloatBase : public rtNoCrtLimitNumericBase + { + static const bool is_specialized = true; + static const bool is_signed = true; + static const bool is_bounded = true; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const int radix = FLT_RADIX; + static const float_denorm_style has_denorm = denorm_present; + static const float_round_style round_style = round_to_nearest; + }; + + /* + * Generic template. + */ + template<typename a_Type> + struct numeric_limits : public rtNoCrtLimitNumericBase + { + /** @todo need a RT_CONSTEXPR_FN etc */ + static constexpr a_Type(min)() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type(max)() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type lowest() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type epsilon() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type round_error() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type infinity() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type quiet_NaN() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type signaling_NaN() RT_NOEXCEPT { return a_Type(); } + static constexpr a_Type denorm_min() RT_NOEXCEPT { return a_Type(); } + }; + + /* const and volatile trickery: */ + template<typename a_Type> struct numeric_limits<const a_Type> : public numeric_limits<a_Type> {}; + template<typename a_Type> struct numeric_limits<volatile a_Type> : public numeric_limits<a_Type> {}; + template<typename a_Type> struct numeric_limits<const volatile a_Type> : public numeric_limits<a_Type> {}; + + /* + * Integer specializations. + */ + template<> + struct numeric_limits<bool> : public rtNoCrtLimitNumericIntBase + { + static constexpr bool(min)() RT_NOEXCEPT { return false; } + static constexpr bool(max)() RT_NOEXCEPT { return true; } + static constexpr bool lowest() RT_NOEXCEPT { return false; } + static constexpr bool epsilon() RT_NOEXCEPT { return false; } + static constexpr bool round_error() RT_NOEXCEPT { return false; } + static constexpr bool infinity() RT_NOEXCEPT { return false; } + static constexpr bool quiet_NaN() RT_NOEXCEPT { return false; } + static constexpr bool signaling_NaN() RT_NOEXCEPT { return false; } + static constexpr bool denorm_min() RT_NOEXCEPT { return false; } + static const int digits = 1; + }; + + template<> + struct numeric_limits<char> : public rtNoCrtLimitNumericIntBase + { + static constexpr char(min)() RT_NOEXCEPT { return CHAR_MIN; } + static constexpr char(max)() RT_NOEXCEPT { return CHAR_MAX; } + static constexpr char lowest() RT_NOEXCEPT { return CHAR_MIN; } + static constexpr char epsilon() RT_NOEXCEPT { return 0; } + static constexpr char round_error() RT_NOEXCEPT { return 0; } + static constexpr char infinity() RT_NOEXCEPT { return 0; } + static constexpr char quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr char signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr char denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = (char)(-1) < 0; + static const bool is_modulo = (char)(-1) > 0; + static const int digits = (char)(-1) < 0 ? CHAR_BIT - 1 : CHAR_BIT; + static const int digits10 = 2; + }; + + template<> + struct numeric_limits<signed char> : public rtNoCrtLimitNumericIntBase + { + static constexpr signed char(min)() RT_NOEXCEPT { return SCHAR_MIN; } + static constexpr signed char(max)() RT_NOEXCEPT { return SCHAR_MAX; } + static constexpr signed char lowest() RT_NOEXCEPT { return SCHAR_MIN; } + static constexpr signed char epsilon() RT_NOEXCEPT { return 0; } + static constexpr signed char round_error() RT_NOEXCEPT { return 0; } + static constexpr signed char infinity() RT_NOEXCEPT { return 0; } + static constexpr signed char quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr signed char signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr signed char denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = true; + static const int digits = CHAR_BIT - 1; + static const int digits10 = 2; + }; + + template<> + struct numeric_limits<unsigned char> : public rtNoCrtLimitNumericIntBase + { + static constexpr unsigned char(min)() RT_NOEXCEPT { return 0; } + static constexpr unsigned char(max)() RT_NOEXCEPT { return UCHAR_MAX; } + static constexpr unsigned char lowest() RT_NOEXCEPT { return 0; } + static constexpr unsigned char epsilon() RT_NOEXCEPT { return 0; } + static constexpr unsigned char round_error() RT_NOEXCEPT { return 0; } + static constexpr unsigned char infinity() RT_NOEXCEPT { return 0; } + static constexpr unsigned char quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned char signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned char denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT; + static const int digits10 = 2; + }; + + /** @todo wchar_t, char8_t, char16_t, char32_t */ + + template<> + struct numeric_limits<short> : public rtNoCrtLimitNumericIntBase + { + static constexpr short(min)() RT_NOEXCEPT { return SHRT_MIN; } + static constexpr short(max)() RT_NOEXCEPT { return SHRT_MAX; } + static constexpr short lowest() RT_NOEXCEPT { return SHRT_MIN; } + static constexpr short epsilon() RT_NOEXCEPT { return 0; } + static constexpr short round_error() RT_NOEXCEPT { return 0; } + static constexpr short infinity() RT_NOEXCEPT { return 0; } + static constexpr short quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr short signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr short denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = true; + static const int digits = CHAR_BIT * sizeof(short) - 1; + static const int digits10 = 4; + }; + + template<> + struct numeric_limits<unsigned short> : public rtNoCrtLimitNumericIntBase + { + static constexpr unsigned short(min)() RT_NOEXCEPT { return 0; } + static constexpr unsigned short(max)() RT_NOEXCEPT { return USHRT_MAX; } + static constexpr unsigned short lowest() RT_NOEXCEPT { return 0; } + static constexpr unsigned short epsilon() RT_NOEXCEPT { return 0; } + static constexpr unsigned short round_error() RT_NOEXCEPT { return 0; } + static constexpr unsigned short infinity() RT_NOEXCEPT { return 0; } + static constexpr unsigned short quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned short signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned short denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(unsigned short); + static const int digits10 = 4; + }; + +# if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) + template<> + struct numeric_limits<wchar_t> : public rtNoCrtLimitNumericIntBase + { + static constexpr wchar_t(min)() RT_NOEXCEPT { return WCHAR_MIN; } + static constexpr wchar_t(max)() RT_NOEXCEPT { return WCHAR_MAX; } + static constexpr wchar_t lowest() RT_NOEXCEPT { return WCHAR_MIN; } + static constexpr wchar_t epsilon() RT_NOEXCEPT { return 0; } + static constexpr wchar_t round_error() RT_NOEXCEPT { return 0; } + static constexpr wchar_t infinity() RT_NOEXCEPT { return 0; } + static constexpr wchar_t quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr wchar_t signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr wchar_t denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(wchar_t); + static const int digits10 = sizeof(wchar_t) == 2 ? 4 : 9; /** @todo ASSUMES wchar_t is either 16 or 32 bits */ + }; +# endif + + template<> + struct numeric_limits<char16_t> : public rtNoCrtLimitNumericIntBase + { + static constexpr char16_t(min)() RT_NOEXCEPT { return 0; } + static constexpr char16_t(max)() RT_NOEXCEPT { return USHRT_MAX; } + static constexpr char16_t lowest() RT_NOEXCEPT { return 0; } + static constexpr char16_t epsilon() RT_NOEXCEPT { return 0; } + static constexpr char16_t round_error() RT_NOEXCEPT { return 0; } + static constexpr char16_t infinity() RT_NOEXCEPT { return 0; } + static constexpr char16_t quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr char16_t signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr char16_t denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(char16_t); + static const int digits10 = 4; + }; + + template<> + struct numeric_limits<int> : public rtNoCrtLimitNumericIntBase + { + static constexpr int(min)() RT_NOEXCEPT { return INT_MIN; } + static constexpr int(max)() RT_NOEXCEPT { return INT_MAX; } + static constexpr int lowest() RT_NOEXCEPT { return INT_MIN; } + static constexpr int epsilon() RT_NOEXCEPT { return 0; } + static constexpr int round_error() RT_NOEXCEPT { return 0; } + static constexpr int infinity() RT_NOEXCEPT { return 0; } + static constexpr int quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr int signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr int denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = true; + static const int digits = CHAR_BIT * sizeof(int) - 1; + static const int digits10 = 9; + }; + + template<> + struct numeric_limits<unsigned int> : public rtNoCrtLimitNumericIntBase + { + static constexpr unsigned int(min)() RT_NOEXCEPT { return 0; } + static constexpr unsigned int(max)() RT_NOEXCEPT { return UINT_MAX; } + static constexpr unsigned int lowest() RT_NOEXCEPT { return 0; } + static constexpr unsigned int epsilon() RT_NOEXCEPT { return 0; } + static constexpr unsigned int round_error() RT_NOEXCEPT { return 0; } + static constexpr unsigned int infinity() RT_NOEXCEPT { return 0; } + static constexpr unsigned int quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned int signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned int denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(unsigned int); + static const int digits10 = 9; + }; + + template<> + struct numeric_limits<char32_t> : public rtNoCrtLimitNumericIntBase + { + static constexpr char32_t(min)() RT_NOEXCEPT { return 0; } + static constexpr char32_t(max)() RT_NOEXCEPT { return UINT_MAX; } + static constexpr char32_t lowest() RT_NOEXCEPT { return 0; } + static constexpr char32_t epsilon() RT_NOEXCEPT { return 0; } + static constexpr char32_t round_error() RT_NOEXCEPT { return 0; } + static constexpr char32_t infinity() RT_NOEXCEPT { return 0; } + static constexpr char32_t quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr char32_t signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr char32_t denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(char32_t); + static const int digits10 = 9; + }; + + template<> + struct numeric_limits<long> : public rtNoCrtLimitNumericIntBase + { + static constexpr long(min)() RT_NOEXCEPT { return LONG_MIN; } + static constexpr long(max)() RT_NOEXCEPT { return LONG_MAX; } + static constexpr long lowest() RT_NOEXCEPT { return LONG_MIN; } + static constexpr long epsilon() RT_NOEXCEPT { return 0; } + static constexpr long round_error() RT_NOEXCEPT { return 0; } + static constexpr long infinity() RT_NOEXCEPT { return 0; } + static constexpr long quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr long signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr long denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = true; + static const int digits = CHAR_BIT * sizeof(long) - 1; + static const int digits10 = sizeof(long) == sizeof(int) ? 9 : 18; + }; + + template<> + struct numeric_limits<unsigned long> : public rtNoCrtLimitNumericIntBase + { + static constexpr unsigned long(min)() RT_NOEXCEPT { return 0; } + static constexpr unsigned long(max)() RT_NOEXCEPT { return ULONG_MAX; } + static constexpr unsigned long lowest() RT_NOEXCEPT { return 0; } + static constexpr unsigned long epsilon() RT_NOEXCEPT { return 0; } + static constexpr unsigned long round_error() RT_NOEXCEPT { return 0; } + static constexpr unsigned long infinity() RT_NOEXCEPT { return 0; } + static constexpr unsigned long quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned long signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned long denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(unsigned long); + static const int digits10 = sizeof(unsigned long) == sizeof(unsigned int) ? 9 : 19; + }; + + template<> + struct numeric_limits<long long> : public rtNoCrtLimitNumericIntBase + { + static constexpr long long(min)() RT_NOEXCEPT { return LLONG_MIN; } + static constexpr long long(max)() RT_NOEXCEPT { return LLONG_MAX; } + static constexpr long long lowest() RT_NOEXCEPT { return LLONG_MIN; } + static constexpr long long epsilon() RT_NOEXCEPT { return 0; } + static constexpr long long round_error() RT_NOEXCEPT { return 0; } + static constexpr long long infinity() RT_NOEXCEPT { return 0; } + static constexpr long long quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr long long signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr long long denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_signed = true; + static const int digits = CHAR_BIT * sizeof(long long) - 1; + static const int digits10 = 18; + }; + + template<> + struct numeric_limits<unsigned long long> : public rtNoCrtLimitNumericIntBase + { + static constexpr unsigned long long(min)() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long(max)() RT_NOEXCEPT { return ULLONG_MAX; } + static constexpr unsigned long long lowest() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long epsilon() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long round_error() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long infinity() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long quiet_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long signaling_NaN() RT_NOEXCEPT { return 0; } + static constexpr unsigned long long denorm_min() RT_NOEXCEPT { return 0; } + + static const bool is_modulo = true; + static const int digits = CHAR_BIT * sizeof(unsigned long long); + static const int digits10 = 19; + }; + + + /* + * Floating point. + */ + template<> + struct numeric_limits<float> : public rtNoCrtLimitNumericFloatBase + { + static constexpr float(min)() RT_NOEXCEPT { return FLT_MIN; } + static constexpr float(max)() RT_NOEXCEPT { return FLT_MAX; } + static constexpr float lowest() RT_NOEXCEPT { return -(FLT_MAX); } + static constexpr float epsilon() RT_NOEXCEPT { return FLT_EPSILON; } + static constexpr float round_error() RT_NOEXCEPT { return 0.5F; } + static constexpr float infinity() RT_NOEXCEPT { return __builtin_huge_valf(); } + static constexpr float quiet_NaN() RT_NOEXCEPT { return __builtin_nanf("0"); } + static constexpr float signaling_NaN() RT_NOEXCEPT { return __builtin_nansf("1"); } + static constexpr float denorm_min() RT_NOEXCEPT { return FLT_TRUE_MIN; } + + static const int digits = FLT_MANT_DIG; + static const int digits10 = FLT_DIG; + static const int max_digits10 = FLT_DECIMAL_DIG; + static const int max_exponent = FLT_MAX_EXP; + static const int max_exponent10 = FLT_MAX_10_EXP; + static const int min_exponent = FLT_MIN_EXP; + static const int min_exponent10 = FLT_MIN_10_EXP; + }; + + template<> + struct numeric_limits<double> : public rtNoCrtLimitNumericFloatBase + { + static constexpr double(min)() RT_NOEXCEPT { return DBL_MIN; } + static constexpr double(max)() RT_NOEXCEPT { return DBL_MAX; } + static constexpr double lowest() RT_NOEXCEPT { return -(DBL_MAX); } + static constexpr double epsilon() RT_NOEXCEPT { return DBL_EPSILON; } + static constexpr double round_error() RT_NOEXCEPT { return 0.5; } + static constexpr double infinity() RT_NOEXCEPT { return __builtin_huge_val(); } + static constexpr double quiet_NaN() RT_NOEXCEPT { return __builtin_nan("0"); } + static constexpr double signaling_NaN() RT_NOEXCEPT { return __builtin_nans("1"); } + static constexpr double denorm_min() RT_NOEXCEPT { return DBL_TRUE_MIN; } + + static const int digits = DBL_MANT_DIG; + static const int digits10 = DBL_DIG; + static const int max_digits10 = DBL_DECIMAL_DIG; + static const int max_exponent = DBL_MAX_EXP; + static const int max_exponent10 = DBL_MAX_10_EXP; + static const int min_exponent = DBL_MIN_EXP; + static const int min_exponent10 = DBL_MIN_10_EXP; + }; + + template<> + struct numeric_limits<long double> : public rtNoCrtLimitNumericFloatBase + { + static constexpr long double(min)() RT_NOEXCEPT { return LDBL_MIN; } + static constexpr long double(max)() RT_NOEXCEPT { return LDBL_MAX; } + static constexpr long double lowest() RT_NOEXCEPT { return -(LDBL_MAX); } + static constexpr long double epsilon() RT_NOEXCEPT { return LDBL_EPSILON; } + static constexpr long double round_error() RT_NOEXCEPT { return 0.5L; } +#if LDBL_DIG == DBL_DIG + static constexpr long double infinity() RT_NOEXCEPT { return __builtin_huge_val(); } + static constexpr long double quiet_NaN() RT_NOEXCEPT { return __builtin_nan("0"); } + static constexpr long double signaling_NaN() RT_NOEXCEPT { return __builtin_nans("1"); } +#else + static constexpr long double infinity() RT_NOEXCEPT { return __builtin_huge_vall(); } + static constexpr long double quiet_NaN() RT_NOEXCEPT { return __builtin_nanl("0"); } + static constexpr long double signaling_NaN() RT_NOEXCEPT { return __builtin_nansl("1"); } +#endif + static constexpr long double denorm_min() RT_NOEXCEPT { return LDBL_TRUE_MIN; } + + static const int digits = LDBL_MANT_DIG; + static const int digits10 = LDBL_DIG; + static const int max_digits10 = LDBL_DECIMAL_DIG; + static const int max_exponent = LDBL_MAX_EXP; + static const int max_exponent10 = LDBL_MAX_10_EXP; + static const int min_exponent = LDBL_MIN_EXP; + static const int min_exponent10 = LDBL_MIN_10_EXP; + }; + + /** @todo more types */ +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_limits */ + diff --git a/include/iprt/nocrt/limits.h b/include/iprt/nocrt/limits.h new file mode 100644 index 00000000..7b2e060b --- /dev/null +++ b/include/iprt/nocrt/limits.h @@ -0,0 +1,109 @@ +/** @file + * IPRT / No-CRT - Our own limits header. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_limits_h +#define IPRT_INCLUDED_nocrt_limits_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +#define CHAR_BIT 8 +#define SCHAR_MAX 0x7f +#define SCHAR_MIN (-0x7f - 1) +#define UCHAR_MAX 0xff +#if 1 /* ASSUMES: signed char */ +# define CHAR_MAX SCHAR_MAX +# define CHAR_MIN SCHAR_MIN +#else +# define CHAR_MAX UCHAR_MAX +# define CHAR_MIN 0 +#endif + +#define WORD_BIT 16 +#define USHRT_MAX 0xffff +#define SHRT_MAX 0x7fff +#define SHRT_MIN (-0x7fff - 1) + +/* ASSUMES 32-bit int */ +#define UINT_MAX 0xffffffffU +#define INT_MAX 0x7fffffff +#define INT_MIN (-0x7fffffff - 1) + +#if defined(RT_ARCH_X86) || defined(RT_OS_WINDOWS) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_ARM32) +# define LONG_BIT 32 +# define ULONG_MAX 0xffffffffU +# define LONG_MAX 0x7fffffff +# define LONG_MIN (-0x7fffffff - 1) +#elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64) || defined(RT_ARCH_ARM64) +# define LONG_BIT 64 +# define ULONG_MAX UINT64_C(0xffffffffffffffff) +# define LONG_MAX INT64_C(0x7fffffffffffffff) +# define LONG_MIN (INT64_C(-0x7fffffffffffffff) - 1) +#else +# error "PORTME" +#endif + +#define LLONG_BIT 64 +#define ULLONG_MAX UINT64_C(0xffffffffffffffff) +#define LLONG_MAX INT64_C(0x7fffffffffffffff) +#define LLONG_MIN (INT64_C(-0x7fffffffffffffff) - 1) + +#undef SIZE_MAX +#undef SIZE_T_MAX +#undef SSIZE_MAX +#undef INTPTR_MAX +#undef UINTPTR_MAX +#if ARCH_BITS == 32 +# define SIZE_T_MAX 0xffffffffU +# define SSIZE_MAX 0x7fffffff +# define INTPTR_MAX 0x7fffffff +# define UINTPTR_MAX 0xffffffffU +#elif ARCH_BITS == 64 +# define SIZE_T_MAX UINT64_C(0xffffffffffffffff) +# define SSIZE_MAX INT64_C(0x7fffffffffffffff) +# define INTPTR_MAX INT64_C(0x7fffffffffffffff) +# define UINTPTR_MAX UINT64_C(0xffffffffffffffff) +#else +# error "huh?" +#endif +#define SIZE_MAX SIZE_T_MAX + +/*#define OFF_MAX __OFF_MAX +#define OFF_MIN __OFF_MIN*/ + +#endif /* !IPRT_INCLUDED_nocrt_limits_h */ + diff --git a/include/iprt/nocrt/malloc.h b/include/iprt/nocrt/malloc.h new file mode 100644 index 00000000..57c5aa4f --- /dev/null +++ b/include/iprt/nocrt/malloc.h @@ -0,0 +1,49 @@ +/** @file + * IPRT / No-CRT - Our own minimal malloc.h header (needed by xmmintrin.h). + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_malloc_h +#define IPRT_INCLUDED_nocrt_malloc_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* Just map it onto stdlib.h and alloca.h for now. */ +#include <stdlib.h> +#ifdef IN_RING3 +# include <iprt/alloca.h> +#endif + +#endif /* !IPRT_INCLUDED_nocrt_malloc_h */ + diff --git a/include/iprt/nocrt/math.h b/include/iprt/nocrt/math.h new file mode 100644 index 00000000..4ae2c48c --- /dev/null +++ b/include/iprt/nocrt/math.h @@ -0,0 +1,859 @@ +/** @file + * IPRT / No-CRT - math.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + * -------------------------------------------------------------------- + * + * This code is based on: + * + * from: @(#)fdlibm.h 5.1 93/09/24 + * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $ + * FreeBSD HEAD 2005-06-xx + * + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifndef IPRT_INCLUDED_nocrt_math_h +#define IPRT_INCLUDED_nocrt_math_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> +/*#include <machine/_limits.h>*/ + +/* from sys/cdefs.h */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif +#undef __pure2 /* darwin: avoid conflict with system headers when doing syntax checking of the headers */ +#define __pure2 + + +/* + * ANSI/POSIX + */ +extern const union __infinity_un { + RTFLOAT64U __uu; + double __ud; +} RT_NOCRT(__infinity); + +extern const union __nanf_un { + RTFLOAT32U __uu; + float __uf; +} RT_NOCRT(__nanf); + +#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __MATH_BUILTIN_CONSTANTS +#endif + +#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) +#define __MATH_BUILTIN_RELOPS +#endif + +#ifndef IPRT_NOCRT_WITHOUT_CONFLICTING_CONSTANTS + +# if defined(__MATH_BUILTIN_CONSTANTS) \ + || (RT_MSC_PREREQ(RT_MSC_VER_VC140) && defined(__cplusplus)) /** @todo when was this added exactly? 2015, 2017 & 2019 has it for C++. */ +# define HUGE_VAL __builtin_huge_val() +# else +# define HUGE_VAL (RT_NOCRT(__infinity).__ud) +# endif + +/* + * XOPEN/SVID + */ +# if 1/* __BSD_VISIBLE || __XSI_VISIBLE*/ +# define M_E 2.7182818284590452354 /* e */ +# define M_LOG2E 1.4426950408889634074 /* log 2e */ +# define M_LOG10E 0.43429448190325182765 /* log 10e */ +# define M_LN2 0.69314718055994530942 /* log e2 */ +# define M_LN10 2.30258509299404568402 /* log e10 */ +# define M_PI 3.14159265358979323846 /* pi */ +# define M_PI_2 1.57079632679489661923 /* pi/2 */ +# define M_PI_4 0.78539816339744830962 /* pi/4 */ +# define M_1_PI 0.31830988618379067154 /* 1/pi */ +# define M_2_PI 0.63661977236758134308 /* 2/pi */ +# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ + +# define MAXFLOAT ((float)3.40282346638528860e+38) +extern int RT_NOCRT(signgam); +# endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +# if 1/* __BSD_VISIBLE*/ +# if 0 +/* Old value from 4.4BSD-Lite math.h; this is probably better. */ +# define HUGE HUGE_VAL +# else +# define HUGE MAXFLOAT +# endif +# endif /* __BSD_VISIBLE */ + +#endif /* !IPRT_NOCRT_WITHOUT_MATH_CONSTANTS */ + +/* + * Most of these functions depend on the rounding mode and have the side + * effect of raising floating-point exceptions, so they are not declared + * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. + */ +RT_C_DECLS_BEGIN +/* + * ANSI/POSIX + */ +int RT_NOCRT(__fpclassifyd)(double) __pure2; +int RT_NOCRT(__fpclassifyf)(float) __pure2; +int RT_NOCRT(__fpclassifyl)(long double) __pure2; +int RT_NOCRT(__isfinitef)(float) __pure2; +int RT_NOCRT(__isfinite)(double) __pure2; +int RT_NOCRT(__isfinitel)(long double) __pure2; +int RT_NOCRT(__isinff)(float) __pure2; +int RT_NOCRT(__isinfl)(long double) __pure2; +int RT_NOCRT(__isnanl)(long double) __pure2; +int RT_NOCRT(__isnormalf)(float) __pure2; +int RT_NOCRT(__isnormal)(double) __pure2; +int RT_NOCRT(__isnormall)(long double) __pure2; +int RT_NOCRT(__signbit)(double) __pure2; +int RT_NOCRT(__signbitf)(float) __pure2; +int RT_NOCRT(__signbitl)(long double) __pure2; + +double RT_NOCRT(acos)(double); +double RT_NOCRT(asin)(double); +double RT_NOCRT(atan)(double); +double RT_NOCRT(atan2)(double, double); +double RT_NOCRT(cos)(double); +double RT_NOCRT(sin)(double); +double RT_NOCRT(tan)(double); + +double RT_NOCRT(cosh)(double); +double RT_NOCRT(sinh)(double); +double RT_NOCRT(tanh)(double); + +double RT_NOCRT(exp)(double); +double RT_NOCRT(frexp)(double, int *); /* fundamentally !__pure2 */ +double RT_NOCRT(ldexp)(double, int); +double RT_NOCRT(log)(double); +double RT_NOCRT(log10)(double); +double RT_NOCRT(modf)(double, double *); /* fundamentally !__pure2 */ + +double RT_NOCRT(pow)(double, double); +double RT_NOCRT(sqrt)(double); + +double RT_NOCRT(ceil)(double); +double RT_NOCRT(fabs)(double) __pure2; +double RT_NOCRT(floor)(double); +double RT_NOCRT(fmod)(double, double); + +/* + * These functions are not in C90. + */ +#if 1 /*__BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE*/ +double RT_NOCRT(acosh)(double); +double RT_NOCRT(asinh)(double); +double RT_NOCRT(atanh)(double); +double RT_NOCRT(cbrt)(double); +double RT_NOCRT(erf)(double); +double RT_NOCRT(erfc)(double); +double RT_NOCRT(exp2)(double); +double RT_NOCRT(expm1)(double); +double RT_NOCRT(fma)(double, double, double); +double RT_NOCRT(hypot)(double, double); +int RT_NOCRT(ilogb)(double) __pure2; +int RT_NOCRT(isinf)(double) __pure2; +int RT_NOCRT(isnan)(double) __pure2; +double RT_NOCRT(lgamma)(double); +long long RT_NOCRT(llrint)(double); +long long RT_NOCRT(llround)(double); +double RT_NOCRT(log1p)(double); +double RT_NOCRT(logb)(double); +long RT_NOCRT(lrint)(double); +long RT_NOCRT(lround)(double); +double RT_NOCRT(nextafter)(double, double); +double RT_NOCRT(remainder)(double, double); +double RT_NOCRT(remquo)(double, double, int *); +double RT_NOCRT(rint)(double); +#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ + +#if 1/* __BSD_VISIBLE || __XSI_VISIBLE*/ +double RT_NOCRT(j0)(double); +double RT_NOCRT(j1)(double); +double RT_NOCRT(jn)(int, double); +double RT_NOCRT(scalb)(double, double); +double RT_NOCRT(y0)(double); +double RT_NOCRT(y1)(double); +double RT_NOCRT(yn)(int, double); + +#if 1/* __XSI_VISIBLE <= 500 || __BSD_VISIBLE*/ +double RT_NOCRT(gamma)(double); +#endif +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +#if 1/* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999*/ +double RT_NOCRT(copysign)(double, double) __pure2; +double RT_NOCRT(fdim)(double, double); +double RT_NOCRT(fmax)(double, double) __pure2; +double RT_NOCRT(fmin)(double, double) __pure2; +double RT_NOCRT(nearbyint)(double); +double RT_NOCRT(round)(double); +double RT_NOCRT(scalbln)(double, long); +double RT_NOCRT(scalbn)(double, int); +double RT_NOCRT(tgamma)(double); +double RT_NOCRT(trunc)(double); +#endif + +/* + * BSD math library entry points + */ +#if 1/* __BSD_VISIBLE*/ +double RT_NOCRT(drem)(double, double); +int RT_NOCRT(finite)(double) __pure2; +int RT_NOCRT(isnanf)(float) __pure2; + +/* + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +double RT_NOCRT(gamma_r)(double, int *); +double RT_NOCRT(lgamma_r)(double, int *); + +/* + * IEEE Test Vector + */ +double RT_NOCRT(significand)(double); +#endif /* __BSD_VISIBLE */ + +/* float versions of ANSI/POSIX functions */ +#if 1/* __ISO_C_VISIBLE >= 1999*/ +float RT_NOCRT(acosf)(float); +float RT_NOCRT(asinf)(float); +float RT_NOCRT(atanf)(float); +float RT_NOCRT(atan2f)(float, float); +float RT_NOCRT(cosf)(float); +float RT_NOCRT(sinf)(float); +float RT_NOCRT(tanf)(float); + +float RT_NOCRT(coshf)(float); +float RT_NOCRT(sinhf)(float); +float RT_NOCRT(tanhf)(float); + +float RT_NOCRT(exp2f)(float); +float RT_NOCRT(expf)(float); +float RT_NOCRT(expm1f)(float); +float RT_NOCRT(frexpf)(float, int *); /* fundamentally !__pure2 */ +int RT_NOCRT(ilogbf)(float) __pure2; +float RT_NOCRT(ldexpf)(float, int); +float RT_NOCRT(log10f)(float); +float RT_NOCRT(log1pf)(float); +float RT_NOCRT(logf)(float); +float RT_NOCRT(modff)(float, float *); /* fundamentally !__pure2 */ + +float RT_NOCRT(powf)(float, float); +float RT_NOCRT(sqrtf)(float); + +float RT_NOCRT(ceilf)(float); +float RT_NOCRT(fabsf)(float) __pure2; +float RT_NOCRT(floorf)(float); +float RT_NOCRT(fmodf)(float, float); +float RT_NOCRT(roundf)(float); + +float RT_NOCRT(erff)(float); +float RT_NOCRT(erfcf)(float); +float RT_NOCRT(hypotf)(float, float); +float RT_NOCRT(lgammaf)(float); + +float RT_NOCRT(acoshf)(float); +float RT_NOCRT(asinhf)(float); +float RT_NOCRT(atanhf)(float); +float RT_NOCRT(cbrtf)(float); +float RT_NOCRT(logbf)(float); +float RT_NOCRT(copysignf)(float, float) __pure2; +long long RT_NOCRT(llrintf)(float); +long long RT_NOCRT(llroundf)(float); +long RT_NOCRT(lrintf)(float); +long RT_NOCRT(lroundf)(float); +float RT_NOCRT(nearbyintf)(float); +float RT_NOCRT(nextafterf)(float, float); +float RT_NOCRT(remainderf)(float, float); +float RT_NOCRT(remquof)(float, float, int *); +float RT_NOCRT(rintf)(float); +float RT_NOCRT(scalblnf)(float, long); +float RT_NOCRT(scalbnf)(float, int); +float RT_NOCRT(truncf)(float); + +float RT_NOCRT(fdimf)(float, float); +float RT_NOCRT(fmaf)(float, float, float); +float RT_NOCRT(fmaxf)(float, float) __pure2; +float RT_NOCRT(fminf)(float, float) __pure2; +#endif + +/* + * float versions of BSD math library entry points + */ +#if 1/* __BSD_VISIBLE*/ +float RT_NOCRT(dremf)(float, float); +int RT_NOCRT(finitef)(float) __pure2; +float RT_NOCRT(gammaf)(float); +float RT_NOCRT(j0f)(float); +float RT_NOCRT(j1f)(float); +float RT_NOCRT(jnf)(int, float); +float RT_NOCRT(scalbf)(float, float); +float RT_NOCRT(y0f)(float); +float RT_NOCRT(y1f)(float); +float RT_NOCRT(ynf)(int, float); + +/* + * Float versions of reentrant version of gamma & lgamma; passes + * signgam back by reference as the second argument; user must + * allocate space for signgam. + */ +float RT_NOCRT(gammaf_r)(float, int *); +float RT_NOCRT(lgammaf_r)(float, int *); + +/* + * float version of IEEE Test Vector + */ +float RT_NOCRT(significandf)(float); +#endif /* __BSD_VISIBLE */ + +/* + * long double versions of ISO/POSIX math functions + */ +#if 1/* __ISO_C_VISIBLE >= 1999*/ +#if 1 /* bird: we've got these */ +long double RT_NOCRT(acoshl)(long double); +long double RT_NOCRT(acosl)(long double); +long double RT_NOCRT(asinhl)(long double); +long double RT_NOCRT(asinl)(long double); +long double RT_NOCRT(atan2l)(long double, long double); +long double RT_NOCRT(atanhl)(long double); +long double RT_NOCRT(atanl)(long double); +long double RT_NOCRT(cbrtl)(long double); +#endif +long double RT_NOCRT(ceill)(long double); +long double RT_NOCRT(copysignl)(long double, long double) __pure2; +#if 1 /* bird */ +long double RT_NOCRT(coshl)(long double); +long double RT_NOCRT(cosl)(long double); +long double RT_NOCRT(erfcl)(long double); +long double RT_NOCRT(erfl)(long double); +long double RT_NOCRT(exp2l)(long double); +long double RT_NOCRT(expl)(long double); +long double RT_NOCRT(expm1l)(long double); +#endif +long double RT_NOCRT(fabsl)(long double) __pure2; +long double RT_NOCRT(fdiml)(long double, long double); +long double RT_NOCRT(floorl)(long double); +long double RT_NOCRT(fmal)(long double, long double, long double); +long double RT_NOCRT(fmaxl)(long double, long double) __pure2; +long double RT_NOCRT(fminl)(long double, long double) __pure2; +#if 1 /* bird */ +long double RT_NOCRT(fmodl)(long double, long double); +#endif +long double RT_NOCRT(frexpl)(long double value, int *); /* fundamentally !__pure2 */ +#if 1 /* bird */ +long double RT_NOCRT(hypotl)(long double, long double); +#endif +int RT_NOCRT(ilogbl)(long double) __pure2; +long double RT_NOCRT(ldexpl)(long double, int); +#if 1 /* bird */ +long double RT_NOCRT(lgammal)(long double); +long long RT_NOCRT(llrintl)(long double); +#endif +long long RT_NOCRT(llroundl)(long double); +#if 1 /* bird */ +long double RT_NOCRT(log10l)(long double); +long double RT_NOCRT(log1pl)(long double); +long double RT_NOCRT(log2l)(long double); +long double RT_NOCRT(logbl)(long double); +long double RT_NOCRT(logl)(long double); +long RT_NOCRT(lrintl)(long double); +#endif +long RT_NOCRT(lroundl)(long double); +#if 1 /* bird */ +long double RT_NOCRT(modfl)(long double, long double *); /* fundamentally !__pure2 */ +long double RT_NOCRT(nanl)(const char *) __pure2; +long double RT_NOCRT(nearbyintl)(long double); +#endif +long double RT_NOCRT(nextafterl)(long double, long double); +double RT_NOCRT(nexttoward)(double, long double); +float RT_NOCRT(nexttowardf)(float, long double); +long double RT_NOCRT(nexttowardl)(long double, long double); +#if 1 /* bird */ +long double RT_NOCRT(powl)(long double, long double); +long double RT_NOCRT(remainderl)(long double, long double); +long double RT_NOCRT(remquol)(long double, long double, int *); +long double RT_NOCRT(rintl)(long double); +#endif +long double RT_NOCRT(roundl)(long double); +long double RT_NOCRT(scalblnl)(long double, long); +long double RT_NOCRT(scalbnl)(long double, int); +#if 1 /* bird: we 've got most of these. */ +long double RT_NOCRT(sinhl)(long double); +long double RT_NOCRT(sinl)(long double); +long double RT_NOCRT(sqrtl)(long double); +long double RT_NOCRT(tanhl)(long double); +long double RT_NOCRT(tanl)(long double); +long double RT_NOCRT(tgammal)(long double); +#endif +long double RT_NOCRT(truncl)(long double); + +/* bird: these were missing, gcc apparently inlines them. */ +double RT_NOCRT(nan)(const char *); +float RT_NOCRT(nanf)(const char *); + +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#ifndef IPRT_NOCRT_WITHOUT_CONFLICTING_CONSTANTS /*def __USE_GNU*/ +/* + * In GLIBC there are long variants of the XOPEN/SVID constant + * block some pages ago. We need this to get the math tests going. + */ +# define M_El 2.7182818284590452353602874713526625L +# define M_LOG2El 1.4426950408889634073599246810018921L +# define M_LOG10El 0.4342944819032518276511289189166051L +# define M_LN2l 0.6931471805599453094172321214581766L +# define M_LN10l 2.3025850929940456840179914546843642L +# define M_PIl 3.1415926535897932384626433832795029L +# define M_PI_2l 1.5707963267948966192313216916397514L +# define M_PI_4l 0.7853981633974483096156608458198757L +# define M_1_PIl 0.3183098861837906715377675267450287L +# define M_2_PIl 0.6366197723675813430755350534900574L +# define M_2_SQRTPIl 1.1283791670955125738961589031215452L +# define M_SQRT2l 1.4142135623730950488016887242096981L +# define M_SQRT1_2l 0.7071067811865475244008443621048490L +#endif /* !IPRT_NOCRT_WITHOUT_MATH_CONSTANTS */ + +#if 1/*def __USE_GNU*/ + +void RT_NOCRT(sincos)(double, double *, double *); +void RT_NOCRT(sincosf)(float, float *, float *); +void RT_NOCRT(sincosl)(long double, long double *, long double *); +float RT_NOCRT(exp10f)(float); +double RT_NOCRT(exp10)(double); +long double RT_NOCRT(exp10l)(long double); +float RT_NOCRT(log2f)(float); +double RT_NOCRT(log2)(double); +long double RT_NOCRT(log2l)(long double); +float RT_NOCRT(tgammaf)(float); +long double RT_NOCRT(significandl)(long double); +long double RT_NOCRT(j0l)(long double); +long double RT_NOCRT(j1l)(long double); +long double RT_NOCRT(jnl)(int, long double); +long double RT_NOCRT(scalbl)(long double, long double); +long double RT_NOCRT(y0l)(long double); +long double RT_NOCRT(y1l)(long double); +long double RT_NOCRT(ynl)(int, long double); +long double RT_NOCRT(lgammal_r)(long double,int *); +long double RT_NOCRT(gammal)(long double); +#endif + + +RT_C_DECLS_END + + +/** @name fpclassify return values + * @{ */ +#define RT_NOCRT_FP_INFINITE 0x01 +#define RT_NOCRT_FP_NAN 0x02 +#define RT_NOCRT_FP_NORMAL 0x04 +#define RT_NOCRT_FP_SUBNORMAL 0x08 +#define RT_NOCRT_FP_ZERO 0x10 +/** @} */ + +/* bird 2022-08-03: moved this block down so we can prototype isnan & isinf without runnning into the macro forms. */ +#ifndef IPRT_NOCRT_WITHOUT_CONFLICTING_CONSTANTS /* __ISO_C_VISIBLE >= 1999*/ +# define FP_ILOGB0 (-__INT_MAX) +# define FP_ILOGBNAN __INT_MAX + +# ifdef __MATH_BUILTIN_CONSTANTS +# define HUGE_VALF __builtin_huge_valf() +# define HUGE_VALL __builtin_huge_vall() +# define INFINITY __builtin_inf() +# define NAN __builtin_nan("") +# elif RT_MSC_PREREQ(RT_MSC_VER_VC140) && defined(__cplusplus) +/** @todo When were these introduced exactly? 2015, 2017 & 2019 has them. + * However, they only work in C++ even if the c1.dll includes the strings. Oh, well. */ +# define HUGE_VALF __builtin_huge_valf() +# define HUGE_VALL __builtin_huge_val() +# define INFINITY __builtin_huge_val() +# define NAN __builtin_nan("0") /* same as we use in climits */ +# else +# define HUGE_VALF (float)HUGE_VAL +# define HUGE_VALL (long double)HUGE_VAL +# define INFINITY HUGE_VALF +# define NAN (__nanf.__uf) +# endif /* __MATH_BUILTIN_CONSTANTS */ + +# ifndef IPRT_NO_CRT +# define MATH_ERRNO 1 +# endif +# define MATH_ERREXCEPT 2 +# define math_errhandling MATH_ERREXCEPT + +/* XXX We need a <machine/math.h>. */ +# if defined(__ia64__) || defined(__sparc64__) +# define FP_FAST_FMA +# endif +# ifdef __ia64__ +# define FP_FAST_FMAL +# endif +# define FP_FAST_FMAF + +/* Symbolic constants to classify floating point numbers. */ +# define FP_INFINITE RT_NOCRT_FP_INFINITE +# define FP_NAN RT_NOCRT_FP_NAN +# define FP_NORMAL RT_NOCRT_FP_NORMAL +# define FP_SUBNORMAL RT_NOCRT_FP_SUBNORMAL +# define FP_ZERO RT_NOCRT_FP_ZERO +# define fpclassify(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(__fpclassifyf)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(__fpclassifyd)(x) \ + : RT_NOCRT(__fpclassifyl)(x)) + +# define isfinite(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(__isfinitef)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(__isfinite)(x) \ + : RT_NOCRT(__isfinitel)(x)) +# define isinf(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(__isinff)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(isinf)(x) \ + : RT_NOCRT(__isinfl)(x)) +# define isnan(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(isnanf)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(isnan)(x) \ + : RT_NOCRT(__isnanl)(x)) +# define isnormal(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(__isnormalf)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(__isnormal)(x) \ + : RT_NOCRT(__isnormall)(x)) + +# ifdef __MATH_BUILTIN_RELOPS +# define isgreater(x, y) __builtin_isgreater((x), (y)) +# define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) +# define isless(x, y) __builtin_isless((x), (y)) +# define islessequal(x, y) __builtin_islessequal((x), (y)) +# define islessgreater(x, y) __builtin_islessgreater((x), (y)) +# define isunordered(x, y) __builtin_isunordered((x), (y)) +# else +# define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) +# define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) +# define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) +# define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) +# define islessgreater(x, y) (!isunordered((x), (y)) && \ + ((x) > (y) || (y) > (x))) +# define isunordered(x, y) (isnan(x) || isnan(y)) +# endif /* __MATH_BUILTIN_RELOPS */ + +# define signbit(x) \ + ((sizeof (x) == sizeof (float)) ? RT_NOCRT(__signbitf)(x) \ + : (sizeof (x) == sizeof (double)) ? RT_NOCRT(__signbit)(x) \ + : RT_NOCRT(__signbitl)(x)) + +typedef double double_t; +typedef float float_t; +#endif /* !IPRT_NOCRT_WITHOUT_MATH_CONSTANTS */ /* __ISO_C_VISIBLE >= 1999 */ + + +#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +/* sed -e "/#/d" -e "/RT_NOCRT/!d" -e "s/^.*RT_NOCRT(\([a-z0-9_]*\)).*$/# define \1 RT_NOCRT(\1)/" */ +# define __fpclassifyf RT_NOCRT(__fpclassifyf) +# define __fpclassifyd RT_NOCRT(__fpclassifyd) +# define __fpclassifyl RT_NOCRT(__fpclassifyl) +# define __isfinitef RT_NOCRT(__isfinitef) +# define __isfinite RT_NOCRT(__isfinite) +# define __isfinitel RT_NOCRT(__isfinitel) +# define __isinff RT_NOCRT(__isinff) +# define __isinfl RT_NOCRT(__isinfl) +# define __isnanl RT_NOCRT(__isnanl) +# define __isnormalf RT_NOCRT(__isnormalf) +# define __isnormal RT_NOCRT(__isnormal) +# define __isnormall RT_NOCRT(__isnormall) +# define __signbitf RT_NOCRT(__signbitf) +# define __signbit RT_NOCRT(__signbit) +# define __signbitl RT_NOCRT(__signbitl) +# define signgam RT_NOCRT(signgam) +# define __fpclassifyd RT_NOCRT(__fpclassifyd) +# define __fpclassifyf RT_NOCRT(__fpclassifyf) +# define __fpclassifyl RT_NOCRT(__fpclassifyl) +# define __isfinitef RT_NOCRT(__isfinitef) +# define __isfinite RT_NOCRT(__isfinite) +# define __isfinitel RT_NOCRT(__isfinitel) +# define __isinff RT_NOCRT(__isinff) +# define __isinfl RT_NOCRT(__isinfl) +# define __isnanl RT_NOCRT(__isnanl) +# define __isnormalf RT_NOCRT(__isnormalf) +# define __isnormal RT_NOCRT(__isnormal) +# define __isnormall RT_NOCRT(__isnormall) +# define __signbit RT_NOCRT(__signbit) +# define __signbitf RT_NOCRT(__signbitf) +# define __signbitl RT_NOCRT(__signbitl) +# define acos RT_NOCRT(acos) +# define asin RT_NOCRT(asin) +# define atan RT_NOCRT(atan) +# define atan2 RT_NOCRT(atan2) +# define cos RT_NOCRT(cos) +# define sin RT_NOCRT(sin) +# define tan RT_NOCRT(tan) +# define cosh RT_NOCRT(cosh) +# define sinh RT_NOCRT(sinh) +# define tanh RT_NOCRT(tanh) +# define exp RT_NOCRT(exp) +# define frexp RT_NOCRT(frexp) +# define ldexp RT_NOCRT(ldexp) +# define log RT_NOCRT(log) +# define log10 RT_NOCRT(log10) +# define modf RT_NOCRT(modf) +# define pow RT_NOCRT(pow) +# define sqrt RT_NOCRT(sqrt) +# define ceil RT_NOCRT(ceil) +# define fabs RT_NOCRT(fabs) +# define floor RT_NOCRT(floor) +# define fmod RT_NOCRT(fmod) +# define acosh RT_NOCRT(acosh) +# define asinh RT_NOCRT(asinh) +# define atanh RT_NOCRT(atanh) +# define cbrt RT_NOCRT(cbrt) +# define erf RT_NOCRT(erf) +# define erfc RT_NOCRT(erfc) +# define exp2 RT_NOCRT(exp2) +# define expm1 RT_NOCRT(expm1) +# define fma RT_NOCRT(fma) +# define hypot RT_NOCRT(hypot) +# define ilogb RT_NOCRT(ilogb) +# define lgamma RT_NOCRT(lgamma) +# define llrint RT_NOCRT(llrint) +# define llround RT_NOCRT(llround) +# define log1p RT_NOCRT(log1p) +# define logb RT_NOCRT(logb) +# define lrint RT_NOCRT(lrint) +# define lround RT_NOCRT(lround) +# define nextafter RT_NOCRT(nextafter) +# define remainder RT_NOCRT(remainder) +# define remquo RT_NOCRT(remquo) +# define rint RT_NOCRT(rint) +# define j0 RT_NOCRT(j0) +# define j1 RT_NOCRT(j1) +# define jn RT_NOCRT(jn) +# define scalb RT_NOCRT(scalb) +# define y0 RT_NOCRT(y0) +# define y1 RT_NOCRT(y1) +# define yn RT_NOCRT(yn) +# define gamma RT_NOCRT(gamma) +# define copysign RT_NOCRT(copysign) +# define fdim RT_NOCRT(fdim) +# define fmax RT_NOCRT(fmax) +# define fmin RT_NOCRT(fmin) +# define nearbyint RT_NOCRT(nearbyint) +# define round RT_NOCRT(round) +# define scalbln RT_NOCRT(scalbln) +# define scalbn RT_NOCRT(scalbn) +# define tgamma RT_NOCRT(tgamma) +# define trunc RT_NOCRT(trunc) +# define drem RT_NOCRT(drem) +# define finite RT_NOCRT(finite) +/*# define isinf RT_NOCRT(isinf) - already a macro */ +/*# define isnan RT_NOCRT(isnan) - already a macro */ +# define isnanf RT_NOCRT(isnanf) +# define gamma_r RT_NOCRT(gamma_r) +# define lgamma_r RT_NOCRT(lgamma_r) +# define significand RT_NOCRT(significand) +# define acosf RT_NOCRT(acosf) +# define asinf RT_NOCRT(asinf) +# define atanf RT_NOCRT(atanf) +# define atan2f RT_NOCRT(atan2f) +# define cosf RT_NOCRT(cosf) +# define sinf RT_NOCRT(sinf) +# define tanf RT_NOCRT(tanf) +# define coshf RT_NOCRT(coshf) +# define sinhf RT_NOCRT(sinhf) +# define tanhf RT_NOCRT(tanhf) +# define exp2f RT_NOCRT(exp2f) +# define expf RT_NOCRT(expf) +# define expm1f RT_NOCRT(expm1f) +# define frexpf RT_NOCRT(frexpf) +# define ilogbf RT_NOCRT(ilogbf) +# define ldexpf RT_NOCRT(ldexpf) +# define log10f RT_NOCRT(log10f) +# define log1pf RT_NOCRT(log1pf) +# define logf RT_NOCRT(logf) +# define modff RT_NOCRT(modff) +# define powf RT_NOCRT(powf) +# define sqrtf RT_NOCRT(sqrtf) +# define ceilf RT_NOCRT(ceilf) +# define fabsf RT_NOCRT(fabsf) +# define floorf RT_NOCRT(floorf) +# define fmodf RT_NOCRT(fmodf) +# define roundf RT_NOCRT(roundf) +# define erff RT_NOCRT(erff) +# define erfcf RT_NOCRT(erfcf) +# define hypotf RT_NOCRT(hypotf) +# define lgammaf RT_NOCRT(lgammaf) +# define acoshf RT_NOCRT(acoshf) +# define asinhf RT_NOCRT(asinhf) +# define atanhf RT_NOCRT(atanhf) +# define cbrtf RT_NOCRT(cbrtf) +# define logbf RT_NOCRT(logbf) +# define copysignf RT_NOCRT(copysignf) +# define llrintf RT_NOCRT(llrintf) +# define llroundf RT_NOCRT(llroundf) +# define lrintf RT_NOCRT(lrintf) +# define lroundf RT_NOCRT(lroundf) +# define nearbyintf RT_NOCRT(nearbyintf) +# define nextafterf RT_NOCRT(nextafterf) +# define remainderf RT_NOCRT(remainderf) +# define remquof RT_NOCRT(remquof) +# define rintf RT_NOCRT(rintf) +# define scalblnf RT_NOCRT(scalblnf) +# define scalbnf RT_NOCRT(scalbnf) +# define truncf RT_NOCRT(truncf) +# define fdimf RT_NOCRT(fdimf) +# define fmaf RT_NOCRT(fmaf) +# define fmaxf RT_NOCRT(fmaxf) +# define fminf RT_NOCRT(fminf) +# define dremf RT_NOCRT(dremf) +# define finitef RT_NOCRT(finitef) +# define gammaf RT_NOCRT(gammaf) +# define j0f RT_NOCRT(j0f) +# define j1f RT_NOCRT(j1f) +# define jnf RT_NOCRT(jnf) +# define scalbf RT_NOCRT(scalbf) +# define y0f RT_NOCRT(y0f) +# define y1f RT_NOCRT(y1f) +# define ynf RT_NOCRT(ynf) +# define gammaf_r RT_NOCRT(gammaf_r) +# define lgammaf_r RT_NOCRT(lgammaf_r) +# define significandf RT_NOCRT(significandf) +# define acoshl RT_NOCRT(acoshl) +# define acosl RT_NOCRT(acosl) +# define asinhl RT_NOCRT(asinhl) +# define asinl RT_NOCRT(asinl) +# define atan2l RT_NOCRT(atan2l) +# define atanhl RT_NOCRT(atanhl) +# define atanl RT_NOCRT(atanl) +# define cbrtl RT_NOCRT(cbrtl) +# define ceill RT_NOCRT(ceill) +# define copysignl RT_NOCRT(copysignl) +# define coshl RT_NOCRT(coshl) +# define cosl RT_NOCRT(cosl) +# define erfcl RT_NOCRT(erfcl) +# define erfl RT_NOCRT(erfl) +# define exp2l RT_NOCRT(exp2l) +# define expl RT_NOCRT(expl) +# define expm1l RT_NOCRT(expm1l) +# define fabsl RT_NOCRT(fabsl) +# define fdiml RT_NOCRT(fdiml) +# define floorl RT_NOCRT(floorl) +# define fmal RT_NOCRT(fmal) +# define fmaxl RT_NOCRT(fmaxl) +# define fminl RT_NOCRT(fminl) +# define fmodl RT_NOCRT(fmodl) +# define frexpl RT_NOCRT(frexpl) +# define hypotl RT_NOCRT(hypotl) +# define ilogbl RT_NOCRT(ilogbl) +# define ldexpl RT_NOCRT(ldexpl) +# define lgammal RT_NOCRT(lgammal) +# define llrintl RT_NOCRT(llrintl) +# define llroundl RT_NOCRT(llroundl) +# define log10l RT_NOCRT(log10l) +# define log1pl RT_NOCRT(log1pl) +# define log2l RT_NOCRT(log2l) +# define logbl RT_NOCRT(logbl) +# define logl RT_NOCRT(logl) +# define lrintl RT_NOCRT(lrintl) +# define lroundl RT_NOCRT(lroundl) +# define modfl RT_NOCRT(modfl) +# define nanl RT_NOCRT(nanl) +# define nearbyintl RT_NOCRT(nearbyintl) +# define nextafterl RT_NOCRT(nextafterl) +# define nexttoward RT_NOCRT(nexttoward) +# define nexttowardf RT_NOCRT(nexttowardf) +# define nexttowardl RT_NOCRT(nexttowardl) +# define powl RT_NOCRT(powl) +# define remainderl RT_NOCRT(remainderl) +# define remquol RT_NOCRT(remquol) +# define rintl RT_NOCRT(rintl) +# define roundl RT_NOCRT(roundl) +# define scalblnl RT_NOCRT(scalblnl) +# define scalbnl RT_NOCRT(scalbnl) +# define sinhl RT_NOCRT(sinhl) +# define sinl RT_NOCRT(sinl) +# define sqrtl RT_NOCRT(sqrtl) +# define tanhl RT_NOCRT(tanhl) +# define tanl RT_NOCRT(tanl) +# define tgammal RT_NOCRT(tgammal) +# define truncl RT_NOCRT(truncl) +# define nan RT_NOCRT(nan) +# define nanf RT_NOCRT(nanf) +# define sincos RT_NOCRT(sincos) +# define sincosf RT_NOCRT(sincosf) +# define sincosl RT_NOCRT(sincosl) +# define exp10f RT_NOCRT(exp10f) +# define exp10 RT_NOCRT(exp10) +# define exp10l RT_NOCRT(exp10l) +# define log2f RT_NOCRT(log2f) +# define log2 RT_NOCRT(log2) +# define log2l RT_NOCRT(log2l) +# define tgammaf RT_NOCRT(tgammaf) +# define significandl RT_NOCRT(significandl) +# define j0l RT_NOCRT(j0l) +# define j1l RT_NOCRT(j1l) +# define jnl RT_NOCRT(jnl) +# define scalbl RT_NOCRT(scalbl) +# define y0l RT_NOCRT(y0l) +# define y1l RT_NOCRT(y1l) +# define ynl RT_NOCRT(ynl) +# define lgammal_r RT_NOCRT(lgammal_r) +# define gammal RT_NOCRT(gammal) +#endif + +/* + * Include inlined implementations. + */ +#ifdef RT_ARCH_AMD64 +# include <iprt/nocrt/amd64/math.h> +#elif defined(RT_ARCH_X86) +# include <iprt/nocrt/x86/math.h> +#endif + +#endif /* !IPRT_INCLUDED_nocrt_math_h */ + diff --git a/include/iprt/nocrt/memory b/include/iprt/nocrt/memory new file mode 100644 index 00000000..6399c414 --- /dev/null +++ b/include/iprt/nocrt/memory @@ -0,0 +1,108 @@ +/** @file + * IPRT / No-CRT - Minimal C++ std::memory. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_memory +#define VBOX_INCLUDED_SRC_nocrt_memory +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/cstddef> +#include <iprt/nocrt/new> + +namespace std +{ + /** + * Simple allocator - not C++11 compliant. + */ + template<class a_Type> class allocator + { + public: + typedef a_Type value_type; + typedef a_Type const &const_reference; + typedef a_Type *pointer; + typedef a_Type const *const_pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + public: + allocator() RT_NOEXCEPT + { } + + allocator(allocator const &a_rThat) RT_NOEXCEPT + { RT_NOREF(a_rThat); } + + ~allocator() + { } + + a_Type *allocate(size_type a_cItems, const void *a_pvHint = NULL) + { + RT_NOREF(a_pvHint); + Assert(a_cItems <= max_size()); /** @todo throw stuff */ + return static_cast<pointer>(::operator new(sizeof(value_type) * a_cItems)); + } + + void deallocate(a_Type *a_paItems, size_type a_cItems) + { + if (a_paItems && a_cItems > 0) + ::operator delete(a_paItems); + } + + size_type max_size() const + { + /* whatever */ +#if ARCH_BITS >= 64 + return _4G / sizeof(value_type); +#else + return _512M / sizeof(value_type); +#endif + } + + void construct(pointer a_pDst, const_reference a_rSrc) + { + ::new (static_cast<void *>(a_pDst)) a_Type(a_rSrc); + } + + void destroy(pointer a_pDst) + { + a_pDst->~value_type(); + } + }; + + /** @todo make_unique and unique */ +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_memory */ + diff --git a/include/iprt/nocrt/new b/include/iprt/nocrt/new new file mode 100644 index 00000000..ce8929c4 --- /dev/null +++ b/include/iprt/nocrt/new @@ -0,0 +1,118 @@ +/** @file + * IPRT / No-CRT - Our own new header. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_new +#define VBOX_INCLUDED_SRC_nocrt_new +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + + +/** MSC declares the operators as cdecl it seems. */ +#ifdef _MSC_VER +# define RT_NEW_DELETE_CDECL __cdecl +#else +# define RT_NEW_DELETE_CDECL +#endif + +/** MSC doesn't use the standard namespace. */ +#ifdef _MSC_VER +# define RT_NEW_DELETE_SIZE_T size_t +#else +# define RT_NEW_DELETE_SIZE_T std::size_t +#endif + +/** The hint that we're throwing std::bad_alloc is not apprecitated by MSC. */ +#ifdef RT_EXCEPTIONS_ENABLED +# ifdef _MSC_VER +# define RT_NEW_DELETE_THROWS_BAD_ALLOC +# define RT_NEW_DELETE_NOTHROW RT_NO_THROW_DEF +# else +# ifdef _GLIBCXX_THROW +# define RT_NEW_DELETE_THROWS_BAD_ALLOC _GLIBCXX_THROW(std::bad_alloc) +# elif defined(__cplusplus) && (__cplusplus + 0) < 201700 +# define RT_NEW_DELETE_THROWS_BAD_ALLOC throw(std::bad_alloc) +# else +# define RT_NEW_DELETE_THROWS_BAD_ALLOC noexcept(false) +# endif +# define RT_NEW_DELETE_NOTHROW throw() +# endif +#else /* !RT_EXCEPTIONS_ENABLED */ +# define RT_NEW_DELETE_THROWS_BAD_ALLOC +# define RT_NEW_DELETE_NOTHROW +#endif /* !RT_EXCEPTIONS_ENABLED */ + + +#ifdef IPRT_NO_CRT + +namespace std +{ + struct nothrow_t + { + explicit nothrow_t() + {} + }; + extern __declspec(selectany) nothrow_t const nothrow; +} + + +void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_THROWS_BAD_ALLOC; +void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW; +void *RT_NEW_DELETE_CDECL operator new(RT_NEW_DELETE_SIZE_T cb, void *pvPlacement) RT_NEW_DELETE_NOTHROW; +void RT_NEW_DELETE_CDECL operator delete(void *pv) RT_NEW_DELETE_NOTHROW; +#ifdef __cpp_sized_deallocation +void RT_NEW_DELETE_CDECL operator delete(void *pv, RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_NOTHROW; +#endif +void RT_NEW_DELETE_CDECL operator delete(void *pv, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW; + + +void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_THROWS_BAD_ALLOC; +void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW; +void *RT_NEW_DELETE_CDECL operator new[](RT_NEW_DELETE_SIZE_T cb, void *pvPlacement) RT_NEW_DELETE_NOTHROW; +void RT_NEW_DELETE_CDECL operator delete[](void * pv) RT_NEW_DELETE_NOTHROW; +#ifdef __cpp_sized_deallocation +void RT_NEW_DELETE_CDECL operator delete[](void * pv, RT_NEW_DELETE_SIZE_T cb) RT_NEW_DELETE_NOTHROW; +#endif +void RT_NEW_DELETE_CDECL operator delete[](void *pv, const std::nothrow_t &) RT_NEW_DELETE_NOTHROW; + + +#else /* IPRT_NO_CRT */ +# include <new> +#endif /* IPRT_NO_CRT */ + +#endif /* !VBOX_INCLUDED_SRC_nocrt_new */ + diff --git a/include/iprt/nocrt/ostream b/include/iprt/nocrt/ostream new file mode 100644 index 00000000..98820e27 --- /dev/null +++ b/include/iprt/nocrt/ostream @@ -0,0 +1,280 @@ +/** @file + * IPRT / No-CRT - Minimal C++ ostream header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_ostream +#define VBOX_INCLUDED_SRC_nocrt_ostream +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* Currently all in the ios header. */ +#include <iprt/nocrt/ios> + +namespace std +{ + /** + * Basic output stream. + */ + template<typename a_CharType, typename a_CharTraits /*= std::char_traits<a_CharType>*/ > + class basic_ostream : public basic_ios<a_CharType, a_CharTraits> + { + protected: + /** Sentry class that performs pre and post output work. */ + class sentry + { + private: + basic_ostream &m_rParent; + + public: + explicit sentry(basic_ostream &a_rParent) + : m_rParent(a_rParent) + { + if (a_rParent.good()) + { + basic_ostream *pTiedStream = a_rParent.tie(); + if (!pTiedStream) + { /* likely? */ } + else + { + pTiedStream->flush(); + if (!pTiedStream->good()) + a_rParent.setstate(failbit); + } + } + } + + explicit operator bool() const + { + return m_rParent.good(); + } + + ~sentry() + { + if ( (m_rParent.flags() & std::ios_base::unitbuf) + && m_rParent.good()) + m_rParent.rdbuf()->pubsync(); + } + }; + + public: + explicit basic_ostream(std::basic_streambuf<a_CharType,a_CharTraits> *a_pBuf) + : basic_ios(a_pBuf) + { } + + /** For cerr initialization. + * @internal */ + explicit basic_ostream(std::basic_streambuf<a_CharType,a_CharTraits> *a_pBuf, + std::basic_ostream<a_CharType, a_CharTraits> *a_pTiedStream, + bool a_fUnbuffered) + : basic_ios(a_pBuf) + { + m_pTiedStream = a_pTiedStream; + if (!a_fUnbuffered) + setf(std::ios_base::unitbuf); + } + + private: + basic_ostream(basic_ostream const &a_rSrc); /* not copyable */ + basic_ostream &operator=(basic_ostream const &a_rSrc); /* not copyable */ + + public: + virtual ~basic_ostream() + { + } + + public: + basic_ostream &put(char_type a_ch) + { + sentry PrePost(*this); + if (PrePost) + { + if (m_pBuf->sputc(a_ch) == traits_type::eof()) + m_fState |= badbit; + } + return *this; + } + + basic_ostream &write(const char_type *a_pchSrc, std::streamsize a_cchToWrite) + { + sentry PrePost(*this); + if (PrePost) + { + std::streamsize cchWritten = m_pBuf->sputn(a_pchSrc, a_cchToWrite); + if (cchWritten != a_cchToWrite) + m_fState |= badbit; + } + return *this; + } + + basic_ostream &flush() + { + if (m_pBuf) + m_pBuf->pubsync(); + return *this; + } + + pos_type tellp() RT_NOEXCEPT; + basic_ostream &seekp(pos_type a_off) RT_NOEXCEPT; + basic_ostream &seekp(off_type a_off, seekdir enmDir) RT_NOEXCEPT; + + /** @name Internal support methods + * @{ */ + inline basic_ostream &intWrite(const char *a_pchSrc, std::streamsize a_cchToWrite); /**< Internal method outputting char buffers. */ + + /** @returns 8, 10 or 16. */ + inline unsigned intGetIntegerBase() const RT_NOEXCEPT + { + switch (m_fFlags & basefield) + { + default: + case dec: return 10; + case hex: return 16; + case oct: return 8; + } + } + + /** @returns RTSTR_F_XXX . */ + inline unsigned intGetIntegerFlags() const RT_NOEXCEPT + { + unsigned fFlags = 0; + if (m_fFlags & uppercase) + fFlags |= RTSTR_F_CAPITAL; + if (m_fFlags & showbase) + fFlags |= RTSTR_F_SPECIAL; + if (m_fFlags & showpos) + fFlags |= RTSTR_F_PLUS; + return fFlags; + } + + basic_ostream &formatInteger(uint64_t a_uValue, uint32_t a_fFlags, unsigned a_uBase = 0) + { + a_fFlags |= intGetIntegerFlags(); + char szTmp[72]; + int cchTmp = RTStrFormatNumber(szTmp, a_uValue, !a_uBase ? intGetIntegerBase() : a_uBase, 0, 0, a_fFlags); + + /** @todo apply cchWidth and padding. */ + + return intWrite(szTmp, cchTmp); + } + + /** @} */ + }; + + /** @name Character and string output. + * @{ */ + /** @todo not sure if this really works... */ + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, char a_ch) + { + return a_rDst.put(a_ch); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, const char *a_psz) + { + return a_rDst.intWrite(a_psz, strlen(a_psz)); + } + /** @} */ + + /** @name Integer formatting. + * @{ */ + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, signed char a_iValue) + { + return a_rDst.formatInteger(a_iValue, RTSTR_F_8BIT | RTSTR_F_VALSIGNED); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, unsigned char a_uValue) + { + return a_rDst.formatInteger(a_uValue, RTSTR_F_8BIT); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, short a_iValue) + { + return a_rDst.formatInteger(a_iValue, RTSTR_F_16BIT | RTSTR_F_VALSIGNED); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, unsigned short a_uValue) + { + return a_rDst.formatInteger(a_uValue, RTSTR_F_16BIT); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, int a_iValue) + { + return a_rDst.formatInteger(a_iValue, RTSTR_F_32BIT | RTSTR_F_VALSIGNED); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, unsigned int a_uValue) + { + return a_rDst.formatInteger(a_uValue, RTSTR_F_32BIT | RTSTR_F_VALSIGNED); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, long a_iValue) + { + return a_rDst.formatInteger(a_iValue, (sizeof(a_iValue) > sizeof(int32_t) ? RTSTR_F_64BIT : RTSTR_F_32BIT)); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, unsigned long a_uValue) + { + return a_rDst.formatInteger(a_uValue, + RTSTR_F_VALSIGNED | (sizeof(a_uValue) > sizeof(uint32_t) ? RTSTR_F_64BIT : RTSTR_F_32BIT)); + } + + template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > + basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, void const *a_pvValue) + { + return a_rDst.formatInteger((uintptr_t)a_pvValue, + (sizeof(a_pvValue) > sizeof(uint32_t) ? RTSTR_F_64BIT : RTSTR_F_32BIT), 16); + } + /** @} */ + + template<> + inline basic_ostream<char> &basic_ostream<char>::intWrite(const char *a_pchSrc, std::streamsize a_cchToWrite) + { + return write(a_pchSrc, a_cchToWrite); + } + + +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_ostream */ + diff --git a/include/iprt/nocrt/process.h b/include/iprt/nocrt/process.h new file mode 100644 index 00000000..f965813c --- /dev/null +++ b/include/iprt/nocrt/process.h @@ -0,0 +1,43 @@ +/** @file + * IPRT / No-CRT - Stub process.h header for MSC compatibility. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_process_h +#define IPRT_INCLUDED_nocrt_process_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#endif /* !IPRT_INCLUDED_nocrt_process_h */ + diff --git a/include/iprt/nocrt/setjmp.h b/include/iprt/nocrt/setjmp.h new file mode 100644 index 00000000..6b2e15af --- /dev/null +++ b/include/iprt/nocrt/setjmp.h @@ -0,0 +1,68 @@ +/** @file + * IPRT / No-CRT - Our own setjmp header. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_setjmp_h +#define IPRT_INCLUDED_nocrt_setjmp_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +RT_C_DECLS_BEGIN + +#ifdef RT_ARCH_AMD64 +# ifdef RT_OS_WINDOWS /* Also saves rsi, rdi and xmm6-xmm15. */ +typedef uint64_t RT_NOCRT(jmp_buf)[10 + (2*10)]; +# else +typedef uint64_t RT_NOCRT(jmp_buf)[8]; +# endif +#else +typedef uint32_t RT_NOCRT(jmp_buf)[6+2]; +#endif + +extern DECL_RETURNS_TWICE(int) RT_NOCRT(setjmp)(RT_NOCRT(jmp_buf)); +extern DECL_NO_RETURN(int) RT_NOCRT(longjmp)(RT_NOCRT(jmp_buf), int); + +#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define jmp_buf RT_NOCRT(jmp_buf) +# define setjmp RT_NOCRT(setjmp) +# define longjmp RT_NOCRT(longjmp) +#endif + +RT_C_DECLS_END + +#endif /* !IPRT_INCLUDED_nocrt_setjmp_h */ + diff --git a/include/iprt/nocrt/signal.h b/include/iprt/nocrt/signal.h new file mode 100644 index 00000000..36ca57b5 --- /dev/null +++ b/include/iprt/nocrt/signal.h @@ -0,0 +1,43 @@ +/** @file + * IPRT / No-CRT - Stub signal.h header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_signal_h +#define IPRT_INCLUDED_nocrt_signal_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#endif /* !IPRT_INCLUDED_nocrt_signal_h */ + diff --git a/include/iprt/nocrt/stdarg.h b/include/iprt/nocrt/stdarg.h new file mode 100644 index 00000000..3a5b039d --- /dev/null +++ b/include/iprt/nocrt/stdarg.h @@ -0,0 +1,45 @@ +/** @file + * IPRT / No-CRT - stdarg.h (-> iprt/stdarg.h). + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stdarg_h +#define IPRT_INCLUDED_nocrt_stdarg_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/stdarg.h> + +#endif /* !IPRT_INCLUDED_nocrt_stdarg_h */ + diff --git a/include/iprt/nocrt/stdbool.h b/include/iprt/nocrt/stdbool.h new file mode 100644 index 00000000..d288ce2c --- /dev/null +++ b/include/iprt/nocrt/stdbool.h @@ -0,0 +1,58 @@ +/** @file + * IPRT / No-CRT - Our own minimal stdbool.h header (needed by softfloat.h). + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stdbool_h +#define IPRT_INCLUDED_nocrt_stdbool_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* The iprt/types.h header should take care of the basics. */ +#include <iprt/types.h> + +#ifndef __cplusplus +# ifndef bool +# define bool _Bool +# endif +# ifndef true +# define true (1) +# endif +# ifndef false +# define false (0) +# endif +#endif + +#endif /* !IPRT_INCLUDED_nocrt_stdbool_h */ + diff --git a/include/iprt/nocrt/stddef.h b/include/iprt/nocrt/stddef.h new file mode 100644 index 00000000..df56a617 --- /dev/null +++ b/include/iprt/nocrt/stddef.h @@ -0,0 +1,48 @@ +/** @file + * IPRT / No-CRT - stddef.h (-> iprt/types.h). + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stddef_h +#define IPRT_INCLUDED_nocrt_stddef_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +#ifndef offsetof +# define offsetof(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member) +#endif + +#endif /* !IPRT_INCLUDED_nocrt_stddef_h */ diff --git a/include/iprt/nocrt/stdint.h b/include/iprt/nocrt/stdint.h new file mode 100644 index 00000000..2b481159 --- /dev/null +++ b/include/iprt/nocrt/stdint.h @@ -0,0 +1,46 @@ +/** @file + * IPRT / No-CRT - Our own minimal stdint.h header (needed by softfloat.h). + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stdint_h +#define IPRT_INCLUDED_nocrt_stdint_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* The iprt/stdint.h header should take care of the basics. */ +#include <iprt/stdint.h> + +#endif /* !IPRT_INCLUDED_nocrt_stdint_h */ + diff --git a/include/iprt/nocrt/stdio.h b/include/iprt/nocrt/stdio.h new file mode 100644 index 00000000..a63b3e49 --- /dev/null +++ b/include/iprt/nocrt/stdio.h @@ -0,0 +1,226 @@ +/** @file + * IPRT / No-CRT - Mostly empty stdio.h. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stdio_h +#define IPRT_INCLUDED_nocrt_stdio_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/stream.h> +#include <iprt/nocrt/sys/types.h> /* errno_t, off_t */ +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +# include <iprt/nocrt/time.h> /* file.h includes fs.h which includes time.h */ +# include <iprt/file.h> /* for RTFILE_SEEK_XXX */ +# include <iprt/assertcompile.h> +#endif + +typedef RTFOFF fpos_t; + + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +/* + * Only for external libraries and such, but even then it would be best to + * check each printf and fprintf call as IPRT isn't 100% compatible... + */ + +/* These are also in unistd.h: */ +# undef SEEK_SET +# define SEEK_SET RTFILE_SEEK_BEGIN +# undef SEEK_CUR +# define SEEK_CUR RTFILE_SEEK_CURRENT +# undef SEEK_END +# define SEEK_END RTFILE_SEEK_END +AssertCompile(SEEK_SET == 0); AssertCompile(SEEK_CUR == 1); AssertCompile(SEEK_END == 2); /* Also in WDK header mmiscapi.h. */ + +# define RT_NOCRT_BUFSIZ 4096 +# define BUFSIZ RT_NOCRT_BUFSIZ + +RT_C_DECLS_BEGIN + +typedef struct RTSTREAM FILE; +# define stdin g_pStdIn +# define stdout g_pStdOut +# define stderr g_pStdErr + +# define printf RTPrintf +# define vprintf RTPrintfV +# define fprintf RTStrmPrintf +# define vfprintf RTStrmPrintfV +int RT_NOCRT(snprintf)(char *, size_t, const char *, ...); +int RT_NOCRT(vsnprintf)(char *, size_t, const char *, va_list); +int RT_NOCRT(scprintf)(const char *, ...); +int RT_NOCRT(vscprintf)(const char *, va_list); + +FILE *RT_NOCRT(fopen)(const char *pszFilename, const char *pszMode); +FILE *RT_NOCRT(fdopen)(int fd, const char *pszMode); +FILE *RT_NOCRT(tmpfile)(void); +errno_t RT_NOCRT(tmpfile_s)(FILE **ppFile); +int RT_NOCRT(fileno)(FILE *pFile); +int RT_NOCRT(fclose)(FILE *pFile); +int RT_NOCRT(fflush)(FILE *pFile); +int RT_NOCRT(setvbuf)(FILE *pFile, char *pchBuf, int iBufferingType, size_t cbBuf); +int RT_NOCRT(fseek)(FILE *pFile, long, int); +int RT_NOCRT(fseeko)(FILE *pFile, off_t, int); +long RT_NOCRT(ftell)(FILE *pFile); +off_t RT_NOCRT(ftello)(FILE *pFile); +size_t RT_NOCRT(fwrite)(void const *pvBuf, size_t cbItem, size_t cItems, FILE *pFile); +int RT_NOCRT(fputs)(const char *psz, FILE *pFile); +int RT_NOCRT(puts)(const char *psz); +int RT_NOCRT(fputc)(int, FILE *pFile); +int RT_NOCRT(putc)(int, FILE *pFile); +size_t RT_NOCRT(fread)(void *pvBuf, size_t cbItem, size_t cItems, FILE *pFile); +int RT_NOCRT(fgetc)(FILE *pFile); +int RT_NOCRT(getc)(FILE *pFile); +int RT_NOCRT(ferror)(FILE *pFile); +void RT_NOCRT(clearerr)(FILE *pFile); +int RT_NOCRT(remove)(const char *pszFilename); +int RT_NOCRT(sscanf)(const char *pszString, const char *pszFormat, ...); +int RT_NOCRT(vsscanf)(const char *pszString, const char *pszFormat, va_list); + +# ifndef RT_NOCRT_EOF /* also in string */ +# define RT_NOCRT_EOF (-1) +# endif +# define EOF RT_NOCRT_EOF + +/* Underscored variants: */ +# define _printf RTPrintf +# define _vprintf RTPrintfV +# define _fprintf RTStrmPrintf +# define _vfprintf RTStrmPrintfV +int RT_NOCRT(_snprintf)(char *, size_t, const char *, ...); +int RT_NOCRT(_vsnprintf)(char *, size_t, const char *, va_list); +int RT_NOCRT(_scprintf)(const char *, ...); +int RT_NOCRT(_vscprintf)(const char *, va_list); + +FILE *RT_NOCRT(_fopen)(const char *pszFilename, const char *pszMode); +FILE *RT_NOCRT(_fdopen)(int fd, const char *pszMode); +FILE *RT_NOCRT(_tmpfile)(void); +errno_t RT_NOCRT(_tmpfile_s)(FILE **ppFile); +int RT_NOCRT(_fileno)(FILE *pFile); +int RT_NOCRT(_fclose)(FILE *pFile); +int RT_NOCRT(_fflush)(FILE *pFile); +int RT_NOCRT(_setvbuf)(FILE *pFile, char *pchBuf, int iBufferingType, size_t cbBuf); +int RT_NOCRT(_fseek)(FILE *pFile, long, int); +int RT_NOCRT(_fseeko)(FILE *pFile, off_t, int); +long RT_NOCRT(_ftell)(FILE *pFile); +off_t RT_NOCRT(_ftello)(FILE *pFile); +size_t RT_NOCRT(_fwrite)(void const *pvBuf, size_t cbItem, size_t cItems, FILE *pFile); +int RT_NOCRT(_fputs)(const char *psz, FILE *pFile); +int RT_NOCRT(_fputc)(int, FILE *pFile); +size_t RT_NOCRT(_fread)(void *pvBuf, size_t cbItem, size_t cItems, FILE *pFile); +int RT_NOCRT(_fgetc)(FILE *pFile); +int RT_NOCRT(_getc)(FILE *pFile); +int RT_NOCRT(_ferror)(FILE *pFile); +void RT_NOCRT(_clearerr)(FILE *pFile); +int RT_NOCRT(_remove)(const char *pszFilename); +int RT_NOCRT(_sscanf)(const char *pszString, const char *pszFormat, ...); +int RT_NOCRT(_vsscanf)(const char *pszString, const char *pszFormat, va_list); + +# define _IONBF (1) /**< No buffering. */ +# define _IOLBF (2) /**< Line buffered. */ +# define _IOFBF (3) /**< Fully buffered. */ + +/* Aliases: */ +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define snprintf RT_NOCRT(snprintf) +# define vsnprintf RT_NOCRT(vsnprintf) +# define scprintf RT_NOCRT(scprintf) +# define vscprintf RT_NOCRT(vscprintf) + +# define fopen RT_NOCRT(fopen) +# define fdopen RT_NOCRT(fdopen) +# define tmpfile RT_NOCRT(tmpfile) +# define tmpfile_s RT_NOCRT(tmpfile_s) +# define fileno RT_NOCRT(fileno) +# define fclose RT_NOCRT(fclose) +# define fflush RT_NOCRT(fflush) +# define setvbuf RT_NOCRT(setvbuf) +# define fseek RT_NOCRT(fseek) +# define fseeko RT_NOCRT(fseeko) +# define ftell RT_NOCRT(ftell) +# define ftello RT_NOCRT(ftello) +# define fwrite RT_NOCRT(fwrite) +# define fputs RT_NOCRT(fputs) +# define puts RT_NOCRT(puts) +# define fputc RT_NOCRT(fputc) +# define fread RT_NOCRT(fread) +# define fgetc RT_NOCRT(fgetc) +# define getc RT_NOCRT(getc) +# define ferror RT_NOCRT(ferror) +# define clearerr RT_NOCRT(clearerr) +# define remove RT_NOCRT(remove) +# define sscanf RT_NOCRT(sscanf) +# define vsscanf RT_NOCRT(vsscanf) + + +/* Underscored variants: */ +# define _snprintf RT_NOCRT(snprintf) +# define _vsnprintf RT_NOCRT(vsnprintf) +# define _scprintf RT_NOCRT(scprintf) +# define _vscprintf RT_NOCRT(vscprintf) + +# define _fopen RT_NOCRT(fopen) +# define _fdopen RT_NOCRT(fdopen) +# define _tmpfile RT_NOCRT(tmpfile) +# define _tmpfile_s RT_NOCRT(tmpfile_s) +# define _fileno RT_NOCRT(fileno) +# define _fclose RT_NOCRT(fclose) +# define _flush RT_NOCRT(fflush) +# define _setvbuf RT_NOCRT(setvbuf) +# define _fseek RT_NOCRT(fseek) +# define _fseeko RT_NOCRT(fseeko) +# define _ftell RT_NOCRT(ftell) +# define _ftello RT_NOCRT(ftello) +# define _fwrite RT_NOCRT(fwrite) +# define _fputs RT_NOCRT(fputs) +# define _puts RT_NOCRT(puts) +# define _fputc RT_NOCRT(fputc) +# define _fread RT_NOCRT(fread) +# define _fgetc RT_NOCRT(fgetc) +# define _getc RT_NOCRT(getc) +# define _ferror RT_NOCRT(ferror) +# define _clearerr RT_NOCRT(clearerr) +# define _remove RT_NOCRT(remove) +# define _sscanf RT_NOCRT(_sscanf) +# define _vsscanf RT_NOCRT(_vsscanf) +# endif + +RT_C_DECLS_END + +#endif + +#endif /* !IPRT_INCLUDED_nocrt_stdio_h */ + diff --git a/include/iprt/nocrt/stdlib.h b/include/iprt/nocrt/stdlib.h new file mode 100644 index 00000000..49868cbe --- /dev/null +++ b/include/iprt/nocrt/stdlib.h @@ -0,0 +1,227 @@ +/** @file + * IPRT / No-CRT - Our minimal stdlib.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_stdlib_h +#define IPRT_INCLUDED_nocrt_stdlib_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/assert.h> +#include <iprt/env.h> +#include <iprt/mem.h> +#include <iprt/nocrt/limits.h> + +RT_C_DECLS_BEGIN + +#define EXIT_SUCCESS RTEXITCODE_SUCCESS +#define EXIT_FAILURE RTEXITCODE_FAILURE + + +typedef void FNRTNOCRTATEXITCALLBACK(void) /*RT_NOEXCEPT*/; +typedef FNRTNOCRTATEXITCALLBACK *PFNRTNOCRTATEXITCALLBACK; +#if defined(_MSC_VER) && defined(RT_WITHOUT_NOCRT_WRAPPERS) /* Clashes with compiler internal prototype or smth. */ +int nocrt_atexit(PFNRTNOCRTATEXITCALLBACK) RT_NOEXCEPT; +# define atexit nocrt_atexit +#else +int RT_NOCRT(atexit)(PFNRTNOCRTATEXITCALLBACK) RT_NOEXCEPT; +#endif + +#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define atexit RT_NOCRT(atexit) +#endif + + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +/* + * Only for external libraries and such. + */ + +DECLINLINE(void *) RT_NOCRT(malloc)(size_t cb) +{ + return RTMemAlloc(cb); +} + +DECLINLINE(void *) RT_NOCRT(calloc)(size_t cItems, size_t cbItem) +{ + return RTMemAllocZ(cItems * cbItem); /* caller responsible for overflow issues. */ +} + +DECLINLINE(void *) RT_NOCRT(realloc)(void *pvOld, size_t cbNew) +{ + return RTMemRealloc(pvOld, cbNew); +} + +DECLINLINE(void) RT_NOCRT(free)(void *pv) +{ + RTMemFree(pv); +} + +DECLINLINE(const char *) RT_NOCRT(getenv)(const char *pszVar) +{ + return RTEnvGet(pszVar); +} + +int RT_NOCRT(abs)(int) RT_NOEXCEPT; +long RT_NOCRT(labs)(long) RT_NOEXCEPT; +long long RT_NOCRT(llabs)(long long) RT_NOEXCEPT; +int RT_NOCRT(rand)(void) RT_NOEXCEPT; +void RT_NOCRT(srand)(unsigned) RT_NOEXCEPT; +long RT_NOCRT(strtol)(const char *psz, char **ppszNext, int iBase) RT_NOEXCEPT; +long long RT_NOCRT(strtoll)(const char *psz, char **ppszNext, int iBase) RT_NOEXCEPT; +unsigned long RT_NOCRT(strtoul)(const char *psz, char **ppszNext, int iBase) RT_NOEXCEPT; +unsigned long long RT_NOCRT(strtoull)(const char *psz, char **ppszNext, int iBase) RT_NOEXCEPT; +int RT_NOCRT(atoi)(const char *psz) RT_NOEXCEPT; +double RT_NOCRT(strtod)(const char *psz, char **ppszNext) RT_NOEXCEPT; +double RT_NOCRT(atof)(const char *psz) RT_NOEXCEPT; +void *RT_NOCRT(bsearch)(const void *pvKey, const void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pvKey, const void *pvEntry)); +void RT_NOCRT(qsort)(void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pv1, const void *pv2)); +void RT_NOCRT(qsort_r)(void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pv1, const void *pv2, void *pvUser), void *pvUser); + +/* Map exit & abort onto fatal assert. */ +DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(exit)(int iExitCode) { AssertFatalMsgFailed(("exit: iExitCode=%d\n", iExitCode)); } +DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(abort)(void) { AssertFatalMsgFailed(("abort\n")); } + +/* + * Underscored versions: + */ +DECLINLINE(void *) RT_NOCRT(_malloc)(size_t cb) +{ + return RTMemAlloc(cb); +} + +DECLINLINE(void *) RT_NOCRT(_calloc)(size_t cItems, size_t cbItem) +{ + return RTMemAllocZ(cItems * cbItem); /* caller responsible for overflow issues. */ +} + +DECLINLINE(void *) RT_NOCRT(_realloc)(void *pvOld, size_t cbNew) +{ + return RTMemRealloc(pvOld, cbNew); +} + +DECLINLINE(void) RT_NOCRT(_free)(void *pv) +{ + RTMemFree(pv); +} + +DECLINLINE(const char *) RT_NOCRT(_getenv)(const char *pszVar) +{ + return RTEnvGet(pszVar); +} + +int RT_NOCRT(_abs)(int); +long RT_NOCRT(_labs)(long); +long long RT_NOCRT(_llabs)(long long); +int RT_NOCRT(_rand)(void); +void RT_NOCRT(_srand)(unsigned); +long RT_NOCRT(_strtol)(const char *psz, char **ppszNext, int iBase); +long long RT_NOCRT(_strtoll)(const char *psz, char **ppszNext, int iBase); +unsigned long RT_NOCRT(_strtoul)(const char *psz, char **ppszNext, int iBase); +unsigned long long RT_NOCRT(_strtoull)(const char *psz, char **ppszNext, int iBase); +int RT_NOCRT(_atoi)(const char *psz); +double RT_NOCRT(_strtod)(const char *psz, char **ppszNext); +double RT_NOCRT(_atof)(const char *psz); +void *RT_NOCRT(_bsearch)(const void *pvKey, const void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pv1, const void *pv2)); +void RT_NOCRT(_qsort)(void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pv1, const void *pv2)); +void RT_NOCRT(_qsort_r)(void *pvBase, size_t cEntries, size_t cbEntry, + int (*pfnCompare)(const void *pv1, const void *pv2, void *pvUser), void *pvUser); + +/* Map exit & abort onto fatal assert. */ +DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(_exit)(int iExitCode) { AssertFatalMsgFailed(("_exit: iExitCode=%d\n", iExitCode)); } +DECL_NO_RETURN(DECLINLINE(void)) RT_NOCRT(_abort)(void) { AssertFatalMsgFailed(("_abort\n")); } + +/* Some windows CRT error control functions we totally ignore (only underscored): */ +# define _set_error_mode(a_Mode) (0) +# define _set_abort_behavior(a_fFlags, a_fMask) (0) + +/* + * No-CRT aliases. + */ +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define malloc RT_NOCRT(malloc) +# define calloc RT_NOCRT(calloc) +# define realloc RT_NOCRT(realloc) +# define free RT_NOCRT(free) +# define getenv RT_NOCRT(getenv) +# define bsearch RT_NOCRT(bsearch) +# define exit RT_NOCRT(exit) +# define abort RT_NOCRT(abort) +# define abs RT_NOCRT(abs) +# define labs RT_NOCRT(labs) +# define llabs RT_NOCRT(llabs) +# define rand RT_NOCRT(rand) +# define srand RT_NOCRT(srand) +# define strtol RT_NOCRT(strtol) +# define strtoll RT_NOCRT(strtoll) +# define strtoul RT_NOCRT(strtoul) +# define strtoull RT_NOCRT(strtoull) +# define atoi RT_NOCRT(atoi) +# define strtod RT_NOCRT(strtod) +# define atof RT_NOCRT(atof) + +# define _malloc RT_NOCRT(malloc) +# define _calloc RT_NOCRT(calloc) +# define _realloc RT_NOCRT(realloc) +# define _free RT_NOCRT(free) +# define _getenv RT_NOCRT(getenv) +# define _bsearch RT_NOCRT(bsearch) +# define _exit RT_NOCRT(exit) +# define _abort RT_NOCRT(abort) +# define _abs RT_NOCRT(abs) +# define _labs RT_NOCRT(labs) +# define _llabs RT_NOCRT(llabs) +# define _rand RT_NOCRT(rand) +# define _srand RT_NOCRT(srand) +# define _strtol RT_NOCRT(strtol) +# define _strtoll RT_NOCRT(strtoll) +# define _strtoul RT_NOCRT(strtoul) +# define _strtoull RT_NOCRT(strtoull) +# define _atoi RT_NOCRT(atoi) +# define _strtod RT_NOCRT(strtod) +# define _atof RT_NOCRT(atof) +# endif + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + + +RT_C_DECLS_END + +#endif /* !IPRT_INCLUDED_nocrt_stdlib_h */ diff --git a/include/iprt/nocrt/string b/include/iprt/nocrt/string new file mode 100644 index 00000000..31897dd1 --- /dev/null +++ b/include/iprt/nocrt/string @@ -0,0 +1,322 @@ +/** @file + * IPRT / No-CRT - Minimal C++ string header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_string +#define VBOX_INCLUDED_SRC_nocrt_string +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/string.h> +#include <iprt/nocrt/cstddef> /* for std::size_t */ +#include <iprt/cpp/ministring.h> + +#ifndef RT_NOCRT_EOF /* also in stdio.h */ +# define RT_NOCRT_EOF (-1) +#endif + +namespace std +{ + using streamoff = ::RTFOFF; + + /** + * @note This should be in iosfwd, not string. + */ + template<typename a_MbStateType> + class fpos + { + protected: + std::streamoff m_off; + a_MbStateType m_MbState; + + public: + fpos() + : m_off(0) + , m_MbState() + { } + + fpos(std::streamoff a_off) + : m_off(a_off) + , m_MbState() + { } + + a_MbStateType state() const RT_NOEXCEPT + { + return m_MbState; + } + + void state(a_MbStateType a_NewMbState) const RT_NOEXCEPT + { + m_MbState = a_NewMbState; + } + }; + using mbstate_t = ::RT_NOCRT(mbstate_t); + using streampos = fpos<std::mbstate_t>; + + /* Use RTCString as std::string, it should be a reasonable match. */ + typedef ::RTCString string; + + /** + * Character traits. + */ + template<typename a_CharType> + struct char_traits + { + /** @name Types + * @{ */ + typedef a_CharType char_type; + typedef unsigned long int_type; + typedef std::streamoff off_type; + typedef std::streampos pos_type; + typedef std::mbstate_t state_type; + /** @} */ + + static void assign(char_type &a_rchDst, const char_type &a_rchSrc) RT_NOEXCEPT + { + a_rchDst = a_rchSrc; + } + + static bool eq(const char_type &a_rchLeft, const char_type &a_rchRight) RT_NOEXCEPT + { + return a_rchLeft == a_rchRight; + } + + static bool lt(const char_type &a_rchLeft, const char_type &a_rchRight) RT_NOEXCEPT + { + return a_rchLeft < a_rchRight; + } + + static std::size_t length(const char_type *a_psz) RT_NOEXCEPT; + static int compare(const char_type *a_pchLeft, const char_type *a_pchRight, std::size_t a_cch) RT_NOEXCEPT; + static const char_type *find(const char_type *a_pchHaystack, std::size_t a_cchHaystack, const char_type &a_rchNeedle) RT_NOEXCEPT; + static char_type *assign(char_type *a_pchDst, std::size_t a_cchDst, char_type a_chFill) RT_NOEXCEPT; + static char_type *copy(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT; + static char_type *move(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT; + + static char_type to_char_type(const int_type &a_riChar) + { + return static_cast<char_type>(a_riChar); + } + + static int_type to_int_type(const char_type &a_rch) + { + return static_cast<int_type>(a_rch); + } + + static bool eq_int_type(const int_type &a_riLeft, const int_type &a_riRight) RT_NOEXCEPT + { + return a_riLeft == a_riRight; + } + + static int_type eof() RT_NOEXCEPT + { + return static_cast<int_type>(RT_NOCRT_EOF); + } + + static int_type not_eof(const int_type &a_riChar) RT_NOEXCEPT + { + if (!eq_int_type(a_riChar, eof())) + return a_riChar; + return to_int_type(char_type()); + } + }; + + template<typename a_CharType> + /*static*/ std::size_t char_traits<a_CharType>::length(const char_type *a_psz) RT_NOEXCEPT + { + const char_type * const pszStart = a_psz; + while (!eq(*a_pszLeft, char_type())) + a_psz++; + return static_cast<std::size_t>(a_psz - pszStart); + } + + template<typename a_CharType> + /*static*/ int char_traits<a_CharType>::compare(const char_type *a_pchLeft, const char_type *a_pchRight, + std::size_t a_cch) RT_NOEXCEPT + { + for (std::size_t off = 0; off < a_cch; off++) + if (eq(a_pchLeft[off], a_pchRight[off])) + { /* likely? */ } + else + return lt(a_pchLeft[off], a_pchRight[off]) ? -1 : 1; + return 0; + } + + template<typename a_CharType> + /*static*/ const typename char_traits<a_CharType>::char_type * + char_traits<a_CharType>::find(const char_type *a_pchHaystack, std::size_t a_cchHaystack, + const char_type &a_rchNeedle) RT_NOEXCEPT + { + while (a_cchHaystack-- > 0) + { + if (eq(*a_pchHaystack, a_rchNeedle)) + return a_pchHaystack; + a_pchHaystack++; + } + return NULL; + } + + template<typename a_CharType> + /*static*/ typename char_traits<a_CharType>::char_type * + char_traits<a_CharType>::assign(char_type *a_pchDst, std::size_t a_cchDst, char_type a_chFill) RT_NOEXCEPT + { + char_type * const pchRet = a_pchDst; + while (a_cchDst-- > 0) + *a_pchDst++ = a_chFill; + return pchRet; + } + + template<typename a_CharType> + /*static*/ typename char_traits<a_CharType>::char_type * + char_traits<a_CharType>::copy(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT + { + char_type * const pchRet = a_pchDst; + while (a_cch-- > 0) + *a_pchDst++ = *a_pchSrc++; + return pchRet; + } + + template<typename a_CharType> + /*static*/ typename char_traits<a_CharType>::char_type * + char_traits<a_CharType>::move(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT + { + char_type * const pchRet = a_pchDst; + char_type volatile *pchDstV = static_cast<char_type const volatile *>(a_pchDst); + char_type const volatile *pchSrcV = static_cast<char_type const volatile *>(a_pchSrc); + if ((uintptr_t)a_pchDst < (uintptr_t)a_pchSrc) + { + /* forward copy */ + while (a_cch-- > 0) + *a_pchDstV++ = *a_pchSrcV++; + } + else + { + /* reverse copy */ + a_pchSrcV += a_cch; + a_pchDstV += a_cch; + while (a_cchDst-- > 0) + *a_pchDstV-- = *a_pchSrcV--; + } + return pchRet; + } + + /* + * Character train specializations. + */ + template <> + struct char_traits<char> + { + typedef char char_type; + typedef int int_type; + typedef std::streamoff off_type; + typedef std::streampos pos_type; + typedef std::mbstate_t state_type; + + static void assign(char_type &a_rchDst, const char_type &a_rchSrc) RT_NOEXCEPT + { + a_rchDst = a_rchSrc; + } + + static bool eq(const char_type &a_rchLeft, const char_type &a_rchRight) RT_NOEXCEPT + { + return a_rchLeft == a_rchRight; + } + + static bool lt(const char_type &a_rchLeft, const char_type &a_rchRight) RT_NOEXCEPT + { + return a_rchLeft < a_rchRight; + } + + static std::size_t length(const char_type *a_psz) RT_NOEXCEPT + { + return ::RT_NOCRT(strlen)(a_psz); + } + + static int compare(const char_type *a_pchLeft, const char_type *a_pchRight, std::size_t a_cch) RT_NOEXCEPT + { + return ::RT_NOCRT(memcmp)(a_pchLeft, a_pchRight, a_cch); + } + + static const char_type *find(const char_type *a_pchHaystack, std::size_t a_cchHaystack, const char_type &a_rchNeedle) RT_NOEXCEPT + { + return static_cast<const char_type *>(::RT_NOCRT(memchr)(a_pchHaystack, a_rchNeedle, a_cchHaystack)); + } + + static char_type *assign(char_type *a_pchDst, std::size_t a_cchDst, char_type a_chFill) RT_NOEXCEPT + { + return static_cast<char_type *>(::RT_NOCRT(memset)(a_pchDst, a_chFill, a_cchDst)); + } + + static char_type *copy(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT + { + return static_cast<char_type *>(::RT_NOCRT(memcpy)(a_pchDst, a_pchSrc, a_cch)); + } + + static char_type *move(char_type *a_pchDst, const char_type *a_pchSrc, std::size_t a_cch) RT_NOEXCEPT + { + return static_cast<char_type *>(::RT_NOCRT(memmove)(a_pchDst, a_pchSrc, a_cch)); + } + + static char_type to_char_type(const int_type &a_riChar) + { + return static_cast<char_type>(a_riChar); + } + + static int_type to_int_type(const char_type &a_rch) + { + return static_cast<int_type>(a_rch); + } + + static bool eq_int_type(const int_type &a_riLeft, const int_type &a_riRight) RT_NOEXCEPT + { + return a_riLeft == a_riRight; + } + + static int_type eof() RT_NOEXCEPT + { + return static_cast<int_type>(RT_NOCRT_EOF); + } + + static int_type not_eof(const int_type &a_riChar) RT_NOEXCEPT + { + if (!eq_int_type(a_riChar, eof())) + return a_riChar; + return 0; + } + }; +} + + +#endif /* !VBOX_INCLUDED_SRC_nocrt_string */ diff --git a/include/iprt/nocrt/string.h b/include/iprt/nocrt/string.h new file mode 100644 index 00000000..b83d0036 --- /dev/null +++ b/include/iprt/nocrt/string.h @@ -0,0 +1,254 @@ +/** @file + * IPRT / No-CRT - string.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_string_h +#define IPRT_INCLUDED_nocrt_string_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +/* Dummy for now, fix when/if needed. */ +typedef struct RT_NOCRT(mbstate_t) +{ + unsigned long whatever; +} RT_NOCRT(mbstate_t); + + +RT_C_DECLS_BEGIN + +void *RT_NOCRT(memchr)(const void *pv, int ch, size_t cb); +int RT_NOCRT(memcmp)(const void *pv1, const void *pv2, size_t cb); +void *RT_NOCRT(memcpy)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(mempcpy)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(memrchr)(const void *pv, int ch, size_t cb); +void *RT_NOCRT(memmove)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(memset)(void *pvDst, int ch, size_t cb); + +char *RT_NOCRT(strcat)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(strncat)(char *pszDst, const char *pszSrc, size_t cch); +char *RT_NOCRT(strchr)(const char *psz, int ch); +char *RT_NOCRT(strrchr)(const char *psz, int ch); +int RT_NOCRT(strcmp)(const char *psz1, const char *psz2); +int RT_NOCRT(strncmp)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(stricmp)(const char *psz1, const char *psz2); +int RT_NOCRT(strnicmp)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(strcmpcase)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(strcoll)(const char *psz1, const char *psz2); +char *RT_NOCRT(strcpy)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(strncpy)(char *pszDst, const char *pszSrc, size_t cch); +char *RT_NOCRT(strcat)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(strncat)(char *pszDst, const char *pszSrc, size_t cch); +size_t RT_NOCRT(strlen)(const char *psz); +size_t RT_NOCRT(strnlen)(const char *psz, size_t cch); +size_t RT_NOCRT(strspn)(const char *psz, const char *pszBreakChars); +size_t RT_NOCRT(strcspn)(const char *psz, const char *pszBreakChars); +char *RT_NOCRT(strpbrk)(const char *psz, const char *pszBreakChars); +char *RT_NOCRT(strstr)(const char *psz, const char *pszSub); +char *RT_NOCRT(strtok)(char *psz, const char *pszDelim); +char *RT_NOCRT(strtok_r)(char *psz, const char *pszDelim, char **ppszSave); +#if 0 /* C++11: */ +char *RT_NOCRT(strtok_s)(char *psz, /*rsize_t*/ size_t cchMax, const char *pszDelim, char **ppszSave); +#else /* Microsoft: */ +char *RT_NOCRT(strtok_s)(char *psz, const char *pszDelim, char **ppszSave); +#endif +size_t RT_NOCRT(strxfrm)(char *pszDst, const char *pszSrc, size_t cch); + +size_t RT_NOCRT(wcslen)(const wchar_t *pwsz); +wchar_t *RT_NOCRT(wcscat)(wchar_t *pwszDst, const wchar_t *pwszSrc); +wchar_t *RT_NOCRT(wcschr)(const wchar_t *pwsz, wchar_t wc); +wchar_t *RT_NOCRT(wcscpy)(wchar_t *pwszDst, const wchar_t *pwszSrc); +int RT_NOCRT(wcsicmp)(const wchar_t *pwsz1, const wchar_t *pwsz2); +size_t RT_NOCRT(wcstombs)(char *pszDst, const wchar_t *pszSrc, size_t cbDst); + + +/* Underscored versions for MSC compatibility (mesa #defines regular to _regular + a lot, which is why we really need these prototypes). */ +void *RT_NOCRT(_memchr)(const void *pv, int ch, size_t cb); +int RT_NOCRT(_memcmp)(const void *pv1, const void *pv2, size_t cb); +void *RT_NOCRT(_memcpy)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(_mempcpy)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(_memrchr)(const void *pv, int ch, size_t cb); +void *RT_NOCRT(_memmove)(void *pvDst, const void *pvSrc, size_t cb); +void *RT_NOCRT(_memset)(void *pvDst, int ch, size_t cb); + +char *RT_NOCRT(_strcat)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(_strncat)(char *pszDst, const char *pszSrc, size_t cch); +char *RT_NOCRT(_strchr)(const char *psz, int ch); +char *RT_NOCRT(_strrchr)(const char *psz, int ch); +int RT_NOCRT(_strcmp)(const char *psz1, const char *psz2); +int RT_NOCRT(_strncmp)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(_stricmp)(const char *psz1, const char *psz2); +int RT_NOCRT(_strnicmp)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(_strcmpcase)(const char *psz1, const char *psz2, size_t cch); +int RT_NOCRT(_strcoll)(const char *psz1, const char *psz2); +char *RT_NOCRT(_strcpy)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(_strncpy)(char *pszDst, const char *pszSrc, size_t cch); +char *RT_NOCRT(_strcat)(char *pszDst, const char *pszSrc); +char *RT_NOCRT(_strncat)(char *pszDst, const char *pszSrc, size_t cch); +size_t RT_NOCRT(_strlen)(const char *psz); +size_t RT_NOCRT(_strnlen)(const char *psz, size_t cch); +size_t RT_NOCRT(_strspn)(const char *psz, const char *pszBreakChars); +size_t RT_NOCRT(_strcspn)(const char *psz, const char *pszBreakChars); +char *RT_NOCRT(_strpbrk)(const char *psz, const char *pszBreakChars); +char *RT_NOCRT(_strstr)(const char *psz, const char *pszSub); +char *RT_NOCRT(_strtok)(char *psz, const char *pszDelim); +char *RT_NOCRT(_strtok_r)(char *psz, const char *pszDelim, char **ppszSave); +#if 0 /* C++11: */ +char *RT_NOCRT(_strtok_s)(char *psz, /*rsize_t*/ size_t cchMax, const char *pszDelim, char **ppszSave); +#else /* Microsoft: */ +char *RT_NOCRT(_strtok_s)(char *psz, const char *pszDelim, char **ppszSave); +#endif +size_t RT_NOCRT(_strxfrm)(char *pszDst, const char *pszSrc, size_t cch); + +size_t RT_NOCRT(_wcslen)(const wchar_t *pwsz); +wchar_t *RT_NOCRT(_wcscat)(wchar_t *pwszDst, const wchar_t *pwszSrc); +wchar_t *RT_NOCRT(_wcschr)(const wchar_t *pwsz, wchar_t wc); +wchar_t *RT_NOCRT(_wcscpy)(wchar_t *pwszDst, const wchar_t *pwszSrc); +int RT_NOCRT(_wcsicmp)(const wchar_t *pwsz1, const wchar_t *pwsz2); +size_t RT_NOCRT(_wcstombs)(char *pszDst, const wchar_t *pszSrc, size_t cbDst); + + +#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define memchr RT_NOCRT(memchr) +# define memcmp RT_NOCRT(memcmp) +# define memcpy RT_NOCRT(memcpy) +# define mempcpy RT_NOCRT(mempcpy) +# define memrchr RT_NOCRT(memrchr) +# define memmove RT_NOCRT(memmove) +# define memset RT_NOCRT(memset) + +# define strcat RT_NOCRT(strcat) +# define strncat RT_NOCRT(strncat) +# define strchr RT_NOCRT(strchr) +# define strrchr RT_NOCRT(strrchr) +# define strcmp RT_NOCRT(strcmp) +# define strncmp RT_NOCRT(strncmp) +# define stricmp RT_NOCRT(stricmp) +# define strnicmp RT_NOCRT(strnicmp) +# define strcmpcase RT_NOCRT(strcmpcase) +# define strcoll RT_NOCRT(strcoll) +# define strcpy RT_NOCRT(strcpy) +# define strncpy RT_NOCRT(strncpy) +# define strcat RT_NOCRT(strcat) +# define strncat RT_NOCRT(strncat) +# define strlen RT_NOCRT(strlen) +# define strnlen RT_NOCRT(strnlen) +# define strspn RT_NOCRT(strspn) +# define strcspn RT_NOCRT(strcspn) +# define strpbrk RT_NOCRT(strpbrk) +# define strstr RT_NOCRT(strstr) +# define strtok RT_NOCRT(strtok) +# define strtok_r RT_NOCRT(strtok_r) +# define strtok_s RT_NOCRT(strtok_s) +# define strxfrm RT_NOCRT(strxfrm) + +# define wcslen RT_NOCRT(wcslen) +# define wcscat RT_NOCRT(wcscat) +# define wcschr RT_NOCRT(wcschr) +# define wcscpy RT_NOCRT(wcscpy) +# define wcsicmp RT_NOCRT(wcsicmp) +# define wcstombs RT_NOCRT(wcstombs) + +/* Underscored: */ +# define _memchr RT_NOCRT(memchr) +# define _memcmp RT_NOCRT(memcmp) +# define _memcpy RT_NOCRT(memcpy) +# define _mempcpy RT_NOCRT(mempcpy) +# define _memrchr RT_NOCRT(memrchr) +# define _memmove RT_NOCRT(memmove) +# define _memset RT_NOCRT(memset) + +# define _strcat RT_NOCRT(strcat) +# define _strncat RT_NOCRT(strncat) +# define _strchr RT_NOCRT(strchr) +# define _strrchr RT_NOCRT(strrchr) +# define _strcmp RT_NOCRT(strcmp) +# define _strncmp RT_NOCRT(strncmp) +# define _stricmp RT_NOCRT(stricmp) +# define _strnicmp RT_NOCRT(strnicmp) +# define _strcmpcase RT_NOCRT(strcmpcase) +# define _strcoll RT_NOCRT(strcoll) +# define _strcpy RT_NOCRT(strcpy) +# define _strncpy RT_NOCRT(strncpy) +# define _strcat RT_NOCRT(strcat) +# define _strncat RT_NOCRT(strncat) +# define _strlen RT_NOCRT(strlen) +# define _strnlen RT_NOCRT(strnlen) +# define _strspn RT_NOCRT(strspn) +# define _strcspn RT_NOCRT(strcspn) +# define _strpbrk RT_NOCRT(strpbrk) +# define _strstr RT_NOCRT(strstr) +# define _strtok RT_NOCRT(strtok) +# define _strtok_r RT_NOCRT(strtok_r) +# define _strtok_s RT_NOCRT(strtok_s) +# define _strxfrm RT_NOCRT(strxfrm) + +# define _wcslen RT_NOCRT(wcslen) +# define _wcscat RT_NOCRT(wcscat) +# define _wcschr RT_NOCRT(wcschr) +# define _wcscpy RT_NOCRT(wcscpy) +# define _wcsicmp RT_NOCRT(wcsicmp) +# define _wcstombs RT_NOCRT(wcstombs) +#endif + + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +/* + * Only for external libraries and such. + */ + +const char *RT_NOCRT(strerror)(int iErrNo); +char *RT_NOCRT(strdup)(const char *pszSrc); + +/* Underscored: */ +const char *RT_NOCRT(_strerror)(int iErrNo); +char *RT_NOCRT(_strdup)(const char *pszSrc); + +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define strerror RT_NOCRT(strerror) +# define strdup RT_NOCRT(strdup) + +/* Underscored: */ +# define _strerror RT_NOCRT(strerror) +# define _strdup RT_NOCRT(strdup) +# endif + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + +RT_C_DECLS_END + +#endif /* !IPRT_INCLUDED_nocrt_string_h */ diff --git a/include/iprt/nocrt/sys/stat.h b/include/iprt/nocrt/sys/stat.h new file mode 100644 index 00000000..0ed81c59 --- /dev/null +++ b/include/iprt/nocrt/sys/stat.h @@ -0,0 +1,138 @@ +/** @file + * IPRT / No-CRT - sys/stat.h + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_sys_stat_h +#define IPRT_INCLUDED_nocrt_sys_stat_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/time.h> /* Establish timespec and timeval before iprt/fs.h includes iprt/time.h. */ +#include <iprt/fs.h> +#include <iprt/nocrt/sys/types.h> +#include <iprt/nocrt/limits.h> + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY + +struct RT_NOCRT(stat) +{ + RTINODE st_ino; + RTDEV st_dev; + RTDEV st_rdev; + RTFMODE st_mode; + uint32_t st_link; + RTUID st_uid; + RTGID st_gid; + RTFOFF st_size; + RTFOFF st_blocks; + uint32_t st_blksize; /**< Not related to st_blocks! */ + time_t st_birthtime; + time_t st_ctime; + time_t st_mtime; + time_t st_atime; +}; + +# define _S_IFIFO RTFS_TYPE_FIFO +# define _S_IFCHR RTFS_TYPE_DEV_CHAR +# define _S_IFDIR RTFS_TYPE_DIRECTORY +# define _S_IFBLK RTFS_TYPE_DEV_BLOCK +# define _S_IFREG RTFS_TYPE_FILE +# define _S_IFLNK RTFS_TYPE_SYMLINK +# define _S_IFSOCK RTFS_TYPE_SOCKET +# define _S_IFWHT RTFS_TYPE_WHITEOUT +# define _S_IFMT RTFS_TYPE_MASK + +# define S_IFIFO _S_IFIFO +# define S_IFCHR _S_IFCHR +# define S_IFDIR _S_IFDIR +# define S_IFBLK _S_IFBLK +# define S_IFREG _S_IFREG +# define S_IFLNK _S_IFLNK +# define S_IFSOCK _S_IFSOCK +# define S_IFWHT _S_IFWHT +# define S_IFMT _S_IFMT + +# define S_ISFIFO(a_fMode) RTFS_IS_FIFO(a_fMode) +# define S_ISCHR(a_fMode) RTFS_IS_DEV_CHAR(a_fMode) +# define S_ISDIR(a_fMode) RTFS_IS_DIRECTORY(a_fMode) +# define S_ISBLK(a_fMode) RTFS_IS_DEV_BLOCK(a_fMode) +# define S_ISREG(a_fMode) RTFS_IS_FILE(a_fMode) +# define S_ISLNK(a_fMode) RTFS_IS_SYMLINK(a_fMode) +# define S_ISSOCK(a_fMode) RTFS_IS_SOCKET(a_fMode) +# define S_ISWHT(a_fMode) RTFS_IS_WHITEOUT(a_fMode) + + +RT_C_DECLS_BEGIN + +int RT_NOCRT(chmod)(const char *pszPath, RTFMODE fMode); +int RT_NOCRT(fchmod)(int fd, RTFMODE fMode); +int RT_NOCRT(fstat)(int fd, struct RT_NOCRT(stat) *pStat); +int RT_NOCRT(lstat)(const char *pszPath, struct RT_NOCRT(stat) *pStat); +int RT_NOCRT(stat)(const char *pszPath, struct RT_NOCRT(stat) *pStat); +RTFMODE RT_NOCRT(umask)(RTFMODE fMode); +int RT_NOCRT(mkdir)(const char *, RTFMODE fMode); + +int RT_NOCRT(_chmod)(const char *pszPath, RTFMODE fMode); +int RT_NOCRT(_fchmod)(int fd, RTFMODE fMode); +int RT_NOCRT(_fstat)(int fd, struct RT_NOCRT(stat) *pStat); +int RT_NOCRT(_lstat)(const char *pszPath, struct RT_NOCRT(stat) *pStat); +int RT_NOCRT(_stat)(const char *pszPath, struct RT_NOCRT(stat) *pStat); +RTFMODE RT_NOCRT(_umask)(RTFMODE fMode); +int RT_NOCRT(_mkdir)(const char *, RTFMODE fMode); + +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define chmod RT_NOCRT(chmod) +# define fchmod RT_NOCRT(fchmod) +# define fstat RT_NOCRT(fstat) +# define lstat RT_NOCRT(lstat) +# define stat RT_NOCRT(stat) +# define umask RT_NOCRT(umask) +# define mkdir RT_NOCRT(mkdir) + +# define _chmod RT_NOCRT(chmod) +# define _fchmod RT_NOCRT(fchmod) +# define _fstat RT_NOCRT(fstat) +# define _lstat RT_NOCRT(lstat) +# define _stat RT_NOCRT(stat) +# define _umask RT_NOCRT(umask) +# define _mkdir RT_NOCRT(mkdir) +# endif + +RT_C_DECLS_END + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + +#endif /* !IPRT_INCLUDED_nocrt_sys_stat_h */ + diff --git a/include/iprt/nocrt/sys/types.h b/include/iprt/nocrt/sys/types.h new file mode 100644 index 00000000..3320200a --- /dev/null +++ b/include/iprt/nocrt/sys/types.h @@ -0,0 +1,66 @@ +/** @file + * IPRT / No-CRT - Our own sys/types header. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_sys_types_h +#define IPRT_INCLUDED_nocrt_sys_types_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#if defined(IPRT_INCLUDED_types_h) && !defined(IPRT_COMPLETED_types_h) +# error "Can't include nocrt/sys/types.h from iprt/types.h" +#endif + +#include <iprt/types.h> + +/* #if !defined(MSC-define) && !defined(GNU/LINUX-define) */ +#if !defined(_DEV_T_DEFINED) && !defined(__dev_t_defined) +typedef RTDEV dev_t; +#endif +#if !defined(_UCRT_RESTORE_CLANG_WARNINGS) /* MSC specific type */ +typedef int errno_t; +#endif +#if !defined(_INO_T_DEFINED) && !defined(__ino_t_defined) +typedef RTINODE ino_t; +#endif +#if !defined(_OFF_T_DEFINED) && !defined(__off_t_defined) +typedef RTFOFF off_t; +#endif +#if !defined(_PID_T_DEFINED) && !defined(__pid_t_defined) +typedef RTPROCESS pid_t; +#endif + +#endif /* !IPRT_INCLUDED_nocrt_sys_types_h */ + diff --git a/include/iprt/nocrt/time.h b/include/iprt/nocrt/time.h new file mode 100644 index 00000000..ab2a8649 --- /dev/null +++ b/include/iprt/nocrt/time.h @@ -0,0 +1,107 @@ +/** @file + * IPRT / No-CRT - Our minimal time.h. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_time_h +#define IPRT_INCLUDED_nocrt_time_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#define RTTIME_INCL_TIMESPEC +/*#define RTTIME_INCL_TIMEVAL*/ +#include <iprt/types.h> +#include <iprt/nocrt/sys/types.h> + +/* #if !defined(MSC-define) && !defined(GNU/LINUX-define) */ +#if !defined(_TIME_T_DEFINED) && !defined(__time_t_defined) +# if defined(RT_OS_WINDOWS) && defined(_USE_32BIT_TIME_T) && ARCH_BITS == 32 +typedef long time_t; +# else +typedef int64_t time_t; +# endif +# ifdef _MSC_VER +typedef int64_t __time64_t; +# endif +#endif /* !_TIME_T_DEFINED */ + +#if !defined(_INC_TIME) /* MSC/UCRT guard */ + +# if !defined(_STRUCT_TIMESPEC) && !defined(__struct_timespec_defined) && !defined(_TIMESPEC_DEFINED) && !defined(__timespec_defined) /* << linux variations, new to old. */ +struct timespec +{ + time_t tv_sec; + long tv_nsec; +}; +# endif + +#if !defined(__struct_tm_defined) +struct tm +{ + int tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year; + int tm_wday, tm_yday, tm_isdst, tm_gmtoff; + const char *tm_zone; +}; +# endif + +#endif /* !_INC_TIME */ + +RT_C_DECLS_BEGIN + +time_t RT_NOCRT(time)(time_t *); +errno_t RT_NOCRT(localtime_s)(struct tm *, const time_t *); /* The Microsoft version, not the C11 one. */ +struct tm *RT_NOCRT(localtime_r)(const time_t *, struct tm *); + +time_t RT_NOCRT(_time)(time_t *); +errno_t RT_NOCRT(_localtime_s)(struct tm *, const time_t *); +struct tm *RT_NOCRT(_localtime_r)(const time_t *, struct tm *); + +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define time RT_NOCRT(time) +# define localtime_s RT_NOCRT(localtime_s) +# define localtime_r RT_NOCRT(localtime_r) + +# define _time RT_NOCRT(time) +# define _localtime_s RT_NOCRT(localtime_s) +# define _localtime_r RT_NOCRT(localtime_r) +# endif + +RT_C_DECLS_END + +#ifdef IPRT_INCLUDED_time_h +# error nocrt/time.h after time.h +#endif + +#endif /* !IPRT_INCLUDED_nocrt_time_h */ + diff --git a/include/iprt/nocrt/type_traits b/include/iprt/nocrt/type_traits new file mode 100644 index 00000000..c8c35b2f --- /dev/null +++ b/include/iprt/nocrt/type_traits @@ -0,0 +1,88 @@ +/** @file + * IPRT / No-CRT - Minimal type_traits C++ header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_type_traits +#define VBOX_INCLUDED_SRC_nocrt_type_traits +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/cdefs.h> + +namespace std +{ + /* + * std::integral_constant + */ + template<typename a_Type, a_Type a_Value> + struct integral_constant + { + static constexpr a_Type value = a_Value; + typedef a_Type value_type; + typedef integral_constant<a_Type, a_Value> type; + constexpr operator value_type() const RT_NOEXCEPT { return value; } + /** @todo operator()() for 2014+ */ + }; + template<typename a_Type, a_Type a_Value> constexpr a_Type integral_constant<a_Type, a_Value>::value; + + /* Helper: */ + template<bool a_Value> using bool_constant = integral_constant<bool, a_Value>; + + /* Specializations: */ + typedef integral_constant<bool, true> true_type; + typedef integral_constant<bool, false> false_type; + + + /* + * std::is_enum + */ + template<typename a_Type> struct is_enum + : integral_constant<bool, __is_enum(a_Type) /* compiler (clan, gcc, msc) builtin */ > + { }; + + /* + * std::underlying_type + */ + template<typename a_Type> struct underlying_type + { + using type = __underlying_type(a_Type); /* compiler (clan, gcc, msc) builtin */ + }; + + template<typename a_Type> using underlying_type_t = typename underlying_type<a_Type>::type; + +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_type_traits */ + diff --git a/include/iprt/nocrt/unistd.h b/include/iprt/nocrt/unistd.h new file mode 100644 index 00000000..270a0739 --- /dev/null +++ b/include/iprt/nocrt/unistd.h @@ -0,0 +1,125 @@ +/** @file + * IPRT / No-CRT - Minimal unistd.h header. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_unistd_h +#define IPRT_INCLUDED_nocrt_unistd_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/sys/types.h> +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY +# include <iprt/nocrt/time.h> /* file.h includes fs.h which includes time.h */ +# include <iprt/file.h> /* for RTFILE_SEEK_XXX */ +# include <iprt/assertcompile.h> +#endif + + +#ifdef IPRT_NO_CRT_FOR_3RD_PARTY + +/* Flags for access: */ +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 + +/* These are also in stdio.h: */ +# undef SEEK_SET +# define SEEK_SET RTFILE_SEEK_BEGIN +# undef SEEK_CUR +# define SEEK_CUR RTFILE_SEEK_CURRENT +# undef SEEK_END +# define SEEK_END RTFILE_SEEK_END +AssertCompile(SEEK_SET == 0); AssertCompile(SEEK_CUR == 1); AssertCompile(SEEK_END == 2); /* Also in WDK header mmiscapi.h. */ + +RT_C_DECLS_BEGIN + +int RT_NOCRT(access)(const char *, int) RT_NOEXCEPT; +int RT_NOCRT(dup)(int) RT_NOEXCEPT; +int RT_NOCRT(dup2)(int, int) RT_NOEXCEPT; +ssize_t RT_NOCRT(read)(int, void *, size_t) RT_NOEXCEPT; +ssize_t RT_NOCRT(write)(int, const void *, size_t) RT_NOEXCEPT; +int RT_NOCRT(close)(int) RT_NOEXCEPT; +int RT_NOCRT(isatty)(int) RT_NOEXCEPT; +char *RT_NOCRT(getcwd)(char *, size_t) RT_NOEXCEPT; +RTPROCESS RT_NOCRT(getpid)(void) RT_NOEXCEPT; +RTPROCESS RT_NOCRT(getppid)(void) RT_NOEXCEPT; +int RT_NOCRT(unlink)(const char *) RT_NOEXCEPT; + +int RT_NOCRT(_access)(const char *, int) RT_NOEXCEPT; +int RT_NOCRT(_dup)(int) RT_NOEXCEPT; +int RT_NOCRT(_dup2)(int, int) RT_NOEXCEPT; +ssize_t RT_NOCRT(_read)(int, void *, size_t) RT_NOEXCEPT; +ssize_t RT_NOCRT(_write)(int, const void *, size_t) RT_NOEXCEPT; +int RT_NOCRT(_close)(int) RT_NOEXCEPT; +int RT_NOCRT(_isatty)(int) RT_NOEXCEPT; +char *RT_NOCRT(_getcwd)(char *, size_t) RT_NOEXCEPT; +RTPROCESS RT_NOCRT(_getpid)(void) RT_NOEXCEPT; +RTPROCESS RT_NOCRT(_getppid)(void) RT_NOEXCEPT; +int RT_NOCRT(_unlink)(const char *) RT_NOEXCEPT; + +# if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define access RT_NOCRT(access) +# define dup RT_NOCRT(dup) +# define dup2 RT_NOCRT(dup2) +# define read RT_NOCRT(read) +# define write RT_NOCRT(write) +# define close RT_NOCRT(close) +# define isatty RT_NOCRT(isatty) +# define getcwd RT_NOCRT(getcwd) +# define getpid RT_NOCRT(getpid) +# define getppid RT_NOCRT(getppid) +# define unlink RT_NOCRT(unlink) + +# define _access RT_NOCRT(access) +# define _dup RT_NOCRT(dup) +# define _dup2 RT_NOCRT(dup2) +# define _read RT_NOCRT(read) +# define _write RT_NOCRT(write) +# define _close RT_NOCRT(close) +# define _isatty RT_NOCRT(isatty) +# define _getcwd RT_NOCRT(getcwd) +# define _getpid RT_NOCRT(getpid) +# define _getppid RT_NOCRT(getppid) +# define _unlink RT_NOCRT(unlink) +# endif + +RT_C_DECLS_END + +#endif /* IPRT_NO_CRT_FOR_3RD_PARTY */ + + +#endif /* !IPRT_INCLUDED_nocrt_unistd_h */ + diff --git a/include/iprt/nocrt/vector b/include/iprt/nocrt/vector new file mode 100644 index 00000000..bee4b734 --- /dev/null +++ b/include/iprt/nocrt/vector @@ -0,0 +1,398 @@ +/** @file + * IPRT / No-CRT - Minimal C++ std::vector. + */ + +/* + * Copyright (C) 2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef VBOX_INCLUDED_SRC_nocrt_vector +#define VBOX_INCLUDED_SRC_nocrt_vector +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/nocrt/memory> + +namespace std +{ + template<typename a_Type, class a_Container> + class RTCNoCrtVectorIterator + { + public: + typedef a_Type &reference; + typedef a_Type *pointer; + typedef typename a_Container::difference_type difference_type; + + protected: + a_Type *m_pItem; + + public: + RTCNoCrtVectorIterator() RT_NOEXCEPT + : m_pItem(NULL) + { } + + RTCNoCrtVectorIterator(a_Type *a_pItem) RT_NOEXCEPT + : m_pItem(a_pItem) + { } + + ~RTCNoCrtVectorIterator() + { + m_pItem = NULL; + } + + /** @name Moving the iterator. + * @{ */ + + RTCNoCrtVectorIterator &operator++() RT_NOEXCEPT + { + ++m_pItem; + return *this; + } + + RTCNoCrtVectorIterator &operator--() RT_NOEXCEPT + { + --m_pItem; + return *this; + } + + RTCNoCrtVectorIterator operator++(int) RT_NOEXCEPT + { + return RTCNoCrtVectorIterator(m_pItem++); + } + + RTCNoCrtVectorIterator operator--(int) RT_NOEXCEPT + { + return RTCNoCrtVectorIterator(m_pItem--); + } + + RTCNoCrtVectorIterator &operator+=(difference_type cItems) RT_NOEXCEPT + { + m_pItem += cItems; + return *this; + } + + RTCNoCrtVectorIterator &operator-=(difference_type cItems) RT_NOEXCEPT + { + m_pItem -= cItems; + return *this; + } + + RTCNoCrtVectorIterator operator+(difference_type cItems) const RT_NOEXCEPT + { + return RTCNoCrtVectorIterator(m_pItem + cItems); + } + + RTCNoCrtVectorIterator operator-(difference_type cItems) const RT_NOEXCEPT + { + return RTCNoCrtVectorIterator(m_pItem - cItems); + } + + /** @} */ + + /** @name Item access + * @{ */ + reference operator*() const RT_NOEXCEPT + { + return *m_pItem; + } + + pointer operator->() const RT_NOEXCEPT + { + return m_pItem; + } + + reference operator[](difference_type iItem) const RT_NOEXCEPT + { + return m_pItem[iItem]; + } + + /** @} */ + + /** Helper for const/non-const iterator comparisons: */ + inline typename a_Container::const_pointer getConst() const RT_NOEXCEPT + { + return m_pItem; + } + }; + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator==(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return a_rLeft.getConst() == a_rRight.getConst(); + } + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator!=(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return a_rLeft.getConst() != a_rRight.getConst(); + } + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator<(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return (uintptr_t)a_rLeft.getConst() < (uintptr_t)a_rRight.getConst(); + } + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator<=(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return (uintptr_t)a_rLeft.getConst() <= (uintptr_t)a_rRight.getConst(); + } + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator>(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return (uintptr_t)a_rLeft.getConst() > (uintptr_t)a_rRight.getConst(); + } + + template<typename a_TypeLeft, typename a_TypeRight, class a_Container> + inline bool operator>=(const RTCNoCrtVectorIterator<a_TypeLeft, a_Container> &a_rLeft, + const RTCNoCrtVectorIterator<a_TypeRight, a_Container> &a_rRight) RT_NOEXCEPT + { + return (uintptr_t)a_rLeft.getConst() >= (uintptr_t)a_rRight.getConst(); + } + + + + template<class a_Type, class a_Allocator = std::allocator<a_Type> > + class vector + { + public: + typedef a_Type value_type; + typedef a_Type &reference; + typedef a_Type const &const_reference; + typedef a_Allocator allocator_type; + typedef typename a_Allocator::size_type size_type; + typedef typename a_Allocator::difference_type difference_type; + typedef typename a_Allocator::pointer pointer; + typedef typename a_Allocator::const_pointer const_pointer; + + typedef RTCNoCrtVectorIterator<a_Type, vector> iterator; + typedef RTCNoCrtVectorIterator<const a_Type, vector> const_iterator; + + protected: + pointer m_paItems; + size_t m_cItems; + size_t m_cAllocated; + allocator_type m_Allocator; + + public: + vector() RT_NOEXCEPT + : m_paItems(NULL) + , m_cItems(0) + , m_cAllocated(0) + { } + + vector(size_type a_cAllocate) + : m_paItems(NULL) + , m_cItems(0) + , m_cAllocated(0) + { + m_paItems = m_Allocator.allocate(a_cAllocate); + if (m_paItems) + m_cAllocated = a_cAllocate; + } + + ~vector() + { + clear(); + } + + /** @name Iterators + * @{ */ + iterator begin() RT_NOEXCEPT + { + return iterator(m_paItems); + } + + const_iterator begin() const RT_NOEXCEPT + { + return const_iterator(m_paItems); + } + + const_iterator cbegin() const RT_NOEXCEPT + { + return const_iterator(m_paItems); + } + + iterator end() RT_NOEXCEPT + { + return iterator(m_paItems + m_cItems); + } + + const_iterator end() const RT_NOEXCEPT + { + return const_iterator(m_paItems + m_cItems); + } + + const_iterator cend() const RT_NOEXCEPT + { + return const_iterator(m_paItems + m_cItems); + } + /** @} */ + + /** @name Element access + * @{ */ + reference operator[](size_type iItem) RT_NOEXCEPT + { + Assert(iItem < m_cAllocated); + return m_paItems[iItem]; + } + + const_reference operator[](size_type iItem) const RT_NOEXCEPT + { + Assert(iItem < m_cAllocated); + return m_paItems[iItem]; + } + + reference front() RT_NOEXCEPT + { + return m_paItems[0]; + } + + const_reference front() const RT_NOEXCEPT + { + return m_paItems[0]; + } + + reference back() RT_NOEXCEPT + { + return m_paItems[m_cItems - 1]; + } + + const_reference back() const RT_NOEXCEPT + { + return m_paItems[m_cItems - 1]; + } + + pointer data() RT_NOEXCEPT + { + return m_paItems; + } + + const_pointer data() const RT_NOEXCEPT + { + return m_paItems; + } + + /** @} */ + + /** @name Capacity + * @{ */ + bool empty() const RT_NOEXCEPT + { + return m_cItems == 0; + } + + size_type size() const RT_NOEXCEPT + { + return m_cItems; + } + + size_type max_size() const RT_NOEXCEPT + { + return m_Allocator.max_size(); + } + + void reserve(size_type a_cNewAllocated) + { + Assert(a_cNewAllocated <= max_size()); + + if (a_cNewAllocated > m_cAllocated) + { + vector Temp(a_cNewAllocated); + if (Temp.m_paItems) + { + /* Copy over the data: */ + size_type const cItems = m_cItems; + const_pointer paSrc = m_paItems; + pointer paDst = Temp.m_paItems; + for (size_type i = 0; i < cItems; Temp.m_cItems = ++i) + m_Allocator.construct(&paDst[i], paSrc[i]); + + /* Swap the data. */ + size_type const cOldAllocated = m_cAllocated; + Temp.m_paItems = m_paItems; + m_paItems = paDst; + m_cAllocated = Temp.m_cAllocated; + Temp.m_cAllocated = cOldAllocated; + } + } + } + + /** @} */ + + /** @name Modifiers + * @{ */ + void push_back(const_reference a_rValue) + { + if (m_cItems < m_cAllocated) + { } + else + { + Assert(m_cItems * 2 >= m_cItems); + reserve(m_cItems < 8 ? 8 : m_cItems * 2); /* This might be non-standard. */ + AssertReturnVoid(m_cItems < m_cAllocated); + } + m_paItems[m_cItems] = a_rValue; + m_cItems++; + } + + void pop_back() RT_NOEXCEPT + { + if (m_cItems > 0) + m_cItems -= 1; + } + + void clear() RT_NOEXCEPT + { + size_type i = m_cItems; + while (i-- > 0) + { + m_Allocator.destroy(&m_paItems[i]); + m_cItems = i; + } + m_Allocator.deallocate(m_paItems, m_cAllocated); + m_paItems = NULL; + m_cAllocated = 0; + } + /** @} */ + }; + +} + +#endif /* !VBOX_INCLUDED_SRC_nocrt_vector */ + diff --git a/include/iprt/nocrt/x86/Makefile.kup b/include/iprt/nocrt/x86/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/include/iprt/nocrt/x86/Makefile.kup diff --git a/include/iprt/nocrt/x86/fenv-x86-amd64.h b/include/iprt/nocrt/x86/fenv-x86-amd64.h new file mode 100644 index 00000000..55199ab8 --- /dev/null +++ b/include/iprt/nocrt/x86/fenv-x86-amd64.h @@ -0,0 +1,219 @@ +/** @file + * IPRT / No-CRT - x86 & AMD64 fenv.h. + */ + +/* + * Copyright (C) 2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_x86_fenv_x86_amd64_h +#define IPRT_INCLUDED_nocrt_x86_fenv_x86_amd64_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +typedef struct RTNOCRTFENV +{ + /** The FPU environment. */ + union + { + uint32_t au32[28/4]; +#ifdef IPRT_INCLUDED_x86_h + X86FSTENV32P Env; +#endif + } fpu; + /** The SSE control & status register. */ + uint32_t fMxCsr; +} RTNOCRTFENV; + +/** Exception flags/mask. */ +typedef uint16_t RTNOCRTFEXCEPT; + +#ifndef IPRT_NOCRT_WITHOUT_CONFLICTING_TYPES +typedef RTNOCRTFENV fenv_t; +typedef RTNOCRTFEXCEPT fexcept_t; +#endif + +/** @name Exception flags (same as X86_FCW_xM, X86_FSW_xE, X86_MXCSR_xE) + * @note The X86_FSW_SF is not covered here as it is more of a sub-type of + * invalid operand exception, and it is not part of MXCSR. + * @{ */ +#define RT_NOCRT_FE_INVALID 0x0001 +#define RT_NOCRT_FE_DENORMAL 0x0002 +#define RT_NOCRT_FE_DIVBYZERO 0x0004 +#define RT_NOCRT_FE_OVERFLOW 0x0008 +#define RT_NOCRT_FE_UNDERFLOW 0x0010 +#define RT_NOCRT_FE_INEXACT 0x0020 +#define RT_NOCRT_FE_ALL_EXCEPT 0x003f +#ifndef IPRT_NOCRT_WITHOUT_MATH_CONSTANTS +# define FE_INVALID RT_NOCRT_FE_INVALID +# define FE_DENORMAL RT_NOCRT_FE_DENORMAL +# define FE_DIVBYZERO RT_NOCRT_FE_DIVBYZERO +# define FE_OVERFLOW RT_NOCRT_FE_OVERFLOW +# define FE_UNDERFLOW RT_NOCRT_FE_UNDERFLOW +# define FE_INEXACT RT_NOCRT_FE_INEXACT +# define FE_ALL_EXCEPT RT_NOCRT_FE_ALL_EXCEPT +#endif +/** @} */ + +/** @name Rounding Modes (same X86_FCW_RC_XXX) + * @{ */ +#define RT_NOCRT_FE_TONEAREST 0x0000 +#define RT_NOCRT_FE_DOWNWARD 0x0400 +#define RT_NOCRT_FE_UPWARD 0x0800 +#define RT_NOCRT_FE_TOWARDZERO 0x0c00 +#define RT_NOCRT_FE_ROUND_MASK 0x0c00 +#ifndef IPRT_NOCRT_WITHOUT_MATH_CONSTANTS +# define FE_TONEAREST RT_NOCRT_FE_TONEAREST +# define FE_DOWNWARD RT_NOCRT_FE_DOWNWARD +# define FE_UPWARD RT_NOCRT_FE_UPWARD +# define FE_TOWARDZERO RT_NOCRT_FE_TOWARDZERO +#endif +/** @} */ + + +/** @name x87 Precision (same X86_FCW_PC_XXX) + * @{ */ +#define RT_NOCRT_PC_FLOAT 0x0000 +#define RT_NOCRT_PC_RSVD 0x0100 +#define RT_NOCRT_PC_DOUBLE 0x0200 +#define RT_NOCRT_PC_EXTENDED 0x0300 +#define RT_NOCRT_PC_MASK 0x0300 +/** @} */ + + +/** @name Special environment pointer values. + * @note Only valid with fesetenv and feupdateenv. + * @note Defined as constants in fesetenv.asm. + * @{ */ +/** The default FPU+SSE environment set, all exceptions disabled (masked). */ +#define RT_NOCRT_FE_DFL_ENV ((RTNOCRTFENV const *)(intptr_t)1) +/** The default FPU+SSE environment set, but all exceptions enabled (unmasked) + * except for RT_NOCRT_FE_DENORMAL. */ +#define RT_NOCRT_FE_NOMASK_ENV ((RTNOCRTFENV const *)(intptr_t)2) +/** The default FPU+SSE environment set, all exceptions disabled (masked), + * double precision (53 bit mantissa). */ +#define RT_NOCRT_FE_PC53_ENV ((RTNOCRTFENV const *)(intptr_t)3) +/** The default FPU+SSE environment set, all exceptions disabled (masked), + * extended double precision (64 bit mantissa). */ +#define RT_NOCRT_FE_PC64_ENV ((RTNOCRTFENV const *)(intptr_t)4) +#ifndef IPRT_NOCRT_WITHOUT_MATH_CONSTANTS +# define FE_DFL_ENV RT_NOCRT_FE_DFL_ENV +# define FE_NOMASK_ENV RT_NOCRT_FE_NOMASK_ENV +# define FE_PC53_ENV RT_NOCRT_FE_PC53_ENV +# define FE_PC64_ENV RT_NOCRT_FE_PC64_ENV +#endif +/** @} */ + +RT_C_DECLS_BEGIN + +int RT_NOCRT(fegetenv)(RTNOCRTFENV *); +int RT_NOCRT(fesetenv)(RTNOCRTFENV const *); +int RT_NOCRT(feholdexcept)(RTNOCRTFENV *); +int RT_NOCRT(feupdateenv)(RTNOCRTFENV const *); + +int RT_NOCRT(fegetround)(void); +int RT_NOCRT(fesetround)(int); + +int RT_NOCRT(fegetexcept)(void); +int RT_NOCRT(feenableexcept)(int); +int RT_NOCRT(fedisableexcept)(int); + +int RT_NOCRT(feclearexcept)(int); +int RT_NOCRT(fetestexcept)(int); +int RT_NOCRT(fegetexceptflag)(RTNOCRTFEXCEPT *, int); +int RT_NOCRT(fesetexceptflag)(RTNOCRTFEXCEPT const *, int); + +int RT_NOCRT(feraiseexcept)(int); + +/* IPRT addition: */ +int RT_NOCRT(fegetx87precision)(void); +int RT_NOCRT(fesetx87precision)(int); + +/* Underscored variants: */ +int RT_NOCRT(_fegetenv)(RTNOCRTFENV *); +int RT_NOCRT(_fesetenv)(RTNOCRTFENV const *); +int RT_NOCRT(_feholdexcept)(RTNOCRTFENV *); +int RT_NOCRT(_feupdateenv)(RTNOCRTFENV const *); + +int RT_NOCRT(_fegetround)(void); +int RT_NOCRT(_fesetround)(int); + +int RT_NOCRT(_fegetexcept)(void); +int RT_NOCRT(_feenableexcept)(int); +int RT_NOCRT(_fedisableexcept)(int); + +int RT_NOCRT(_feclearexcept)(int); +int RT_NOCRT(_fetestexcept)(int); +int RT_NOCRT(_fegetexceptflag)(RTNOCRTFEXCEPT *, int); +int RT_NOCRT(_fesetexceptflag)(RTNOCRTFEXCEPT const *, int); + +int RT_NOCRT(_feraiseexcept)(int); + +/* Aliases: */ +#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) && !defined(RT_WITHOUT_NOCRT_WRAPPER_ALIASES) +# define fegetenv RT_NOCRT(fegetenv) +# define fesetenv RT_NOCRT(fesetenv) +# define feholdexcept RT_NOCRT(feholdexcept) +# define feupdateenv RT_NOCRT(feupdateenv) +# define fegetround RT_NOCRT(fegetround) +# define fesetround RT_NOCRT(fesetround) +# define fegetexcept RT_NOCRT(fegetexcept) +# define feenableexcept RT_NOCRT(feenableexcept) +# define fedisableexcept RT_NOCRT(fedisableexcept) +# define feclearexcept RT_NOCRT(feclearexcept) +# define fetestexcept RT_NOCRT(fetestexcept) +# define fegetexceptflag RT_NOCRT(fegetexceptflag) +# define fesetexceptflag RT_NOCRT(fesetexceptflag) +# define feraiseexcept RT_NOCRT(feraiseexcept) + +/* Underscored variants: */ +# define _fegetenv RT_NOCRT(fegetenv) +# define _fesetenv RT_NOCRT(fesetenv) +# define _feholdexcept RT_NOCRT(feholdexcept) +# define _feupdateenv RT_NOCRT(feupdateenv) +# define _fegetround RT_NOCRT(fegetround) +# define _fesetround RT_NOCRT(fesetround) +# define _fegetexcept RT_NOCRT(fegetexcept) +# define _feenableexcept RT_NOCRT(feenableexcept) +# define _fedisableexcept RT_NOCRT(fedisableexcept) +# define _feclearexcept RT_NOCRT(feclearexcept) +# define _fetestexcept RT_NOCRT(fetestexcept) +# define _fegetexceptflag RT_NOCRT(fegetexceptflag) +# define _fesetexceptflag RT_NOCRT(fesetexceptflag) +# define _feraiseexcept RT_NOCRT(feraiseexcept) +#endif + +RT_C_DECLS_END + +#endif /* !IPRT_INCLUDED_nocrt_x86_fenv_x86_amd64_h */ + diff --git a/include/iprt/nocrt/x86/math.h b/include/iprt/nocrt/x86/math.h new file mode 100644 index 00000000..1aa223a3 --- /dev/null +++ b/include/iprt/nocrt/x86/math.h @@ -0,0 +1,114 @@ +/** @file + * IPRT / No-CRT - math.h, x86 inlined functions. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + +#ifndef IPRT_INCLUDED_nocrt_x86_math_h +#define IPRT_INCLUDED_nocrt_x86_math_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/asm.h> + +#if RT_INLINE_ASM_GNU_STYLE + +DECLINLINE(long double) inline_atan2l(long double lrd1, long double lrd2) +{ + long double lrdResult; + __asm__ __volatile__("fpatan" + : "=t" (lrdResult) + : "u" (lrd1), + "0" (lrd2) + : "st(1)"); + return lrdResult; +} + +DECLINLINE(long double) inline_rintl(long double lrd) +{ + long double lrdResult; + __asm__ __volatile__("frndint" + : "=t" (lrdResult) + : "0" (lrd)); + return lrdResult; +} + +DECLINLINE(float) inline_rintf(float rf) +{ + return (float)inline_rintl(rf); +} + +DECLINLINE(double) inline_rint(double rd) +{ + return (double)inline_rintl(rd); +} + +DECLINLINE(long double) inline_sqrtl(long double lrd) +{ + long double lrdResult; + __asm__ __volatile__("fsqrt" + : "=t" (lrdResult) + : "0" (lrd)); + return lrdResult; +} + +DECLINLINE(float) inline_sqrtf(float rf) +{ + return (float)inline_sqrtl(rf); +} + +DECLINLINE(double) inline_sqrt(double rd) +{ + return (double)inline_sqrtl(rd); +} + + +# undef atan2l +# define atan2l(lrd1, lrd2) inline_atan2l(lrd1, lrd2) +# undef rint +# define rint(rd) inline_rint(rd) +# undef rintf +# define rintf(rf) inline_rintf(rf) +# undef rintl +# define rintl(lrd) inline_rintl(lrd) +# undef sqrt +# define sqrt(rd) inline_sqrt(rd) +# undef sqrtf +# define sqrtf(rf) inline_sqrtf(rf) +# undef sqrtl +# define sqrtl(lrd) inline_sqrtl(lrd) + +#endif /* RT_INLINE_ASM_GNU_STYLE */ + +#endif /* !IPRT_INCLUDED_nocrt_x86_math_h */ + |