diff options
Diffstat (limited to 'nihil.core')
| -rw-r--r-- | nihil.core/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | nihil.core/errc.cc | 51 | ||||
| -rw-r--r-- | nihil.core/errc.ccm | 44 | ||||
| -rw-r--r-- | nihil.core/nihil.core.ccm | 9 | ||||
| -rw-r--r-- | nihil.core/nihil.hh | 26 |
5 files changed, 142 insertions, 0 deletions
diff --git a/nihil.core/CMakeLists.txt b/nihil.core/CMakeLists.txt new file mode 100644 index 0000000..2a7b3e2 --- /dev/null +++ b/nihil.core/CMakeLists.txt @@ -0,0 +1,12 @@ +# This source code is released into the public domain. + +add_library(nihil.core STATIC) +target_include_directories(nihil.core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_sources(nihil.core + PUBLIC FILE_SET modules TYPE CXX_MODULES FILES + nihil.core.ccm + errc.ccm + + PRIVATE + errc.cc +) diff --git a/nihil.core/errc.cc b/nihil.core/errc.cc new file mode 100644 index 0000000..35c9d8f --- /dev/null +++ b/nihil.core/errc.cc @@ -0,0 +1,51 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <string> +#include <system_error> + +module nihil.core; + +namespace nihil { + +struct nihil_error_category final : std::error_category { + [[nodiscard]] auto name() const noexcept -> char const * override; + [[nodiscard]] auto message(int err) const -> std::string override; +}; + +[[nodiscard]] auto nihil_category() noexcept -> std::error_category & +{ + static auto category = nihil_error_category(); + return category; +} + +auto make_error_condition(errc ec) -> std::error_condition +{ + return {static_cast<int>(ec), nihil_category()}; +} + +auto nihil_error_category::name() const noexcept -> char const * +{ + return "nihil"; +} + +auto nihil_error_category::message(int err) const -> std::string +{ + switch (static_cast<errc>(err)) { + case errc::no_error: + return "No error"; + case errc::incomplete_command: + return "Incomplete command"; + case errc::empty_string: + return "Empty string is not permitted"; + case errc::invalid_unit: + return "Invalid unit specifier"; + default: + return "Undefined error"; + } +} + +} // namespace nihil diff --git a/nihil.core/errc.ccm b/nihil.core/errc.ccm new file mode 100644 index 0000000..c597faf --- /dev/null +++ b/nihil.core/errc.ccm @@ -0,0 +1,44 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <string> +#include <system_error> + +export module nihil.core:errc; + +namespace nihil { + +export enum struct errc { + no_error = 0, + + /* + * nihil.command + */ + + incomplete_command, + + /* + * nihil.util + */ + + // Empty string is not allowed. + empty_string, + + // Invalid unit, e.g. in parse_size() + invalid_unit, +}; + +export [[nodiscard]] auto nihil_category() noexcept -> std::error_category &; +export [[nodiscard]] auto make_error_condition(errc ec) -> std::error_condition; + +} // namespace nihil + +namespace std { + +export template<> +struct is_error_condition_enum<nihil::errc> : true_type {}; + +} // namespace std diff --git a/nihil.core/nihil.core.ccm b/nihil.core/nihil.core.ccm new file mode 100644 index 0000000..a7a4100 --- /dev/null +++ b/nihil.core/nihil.core.ccm @@ -0,0 +1,9 @@ +/* + * This source code is released into the public domain. + */ + +module; + +export module nihil.core; + +export import :errc; diff --git a/nihil.core/nihil.hh b/nihil.core/nihil.hh new file mode 100644 index 0000000..cd7e789 --- /dev/null +++ b/nihil.core/nihil.hh @@ -0,0 +1,26 @@ +/* +* This source code is released into the public domain. + */ + +#ifndef NIHIL_HH_INCLUDED +#define NIHIL_HH_INCLUDED + +#if __has_include(<sys/param.h>) +# include <sys/param.h> +#endif + +#if defined(__FreeBSD_version) + +/* fexecve() added in FreeBSD 8.0 */ +#if (__FreeBSD_version >= 800000) +# define NIHIL_HAVE_FEXECVE +#endif + +/* getenv_r() added in FreeBSD 15.0 */ +#if (__FreeBSD_version >= 1500000) +# define NIHIL_HAVE_GETENV_R +#endif + +#endif // defined(__FreeBSD_version) + +#endif // !NIHIL_HH_INCLUDED |
