diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/kstd/posix.hpp | 85 | ||||
| -rw-r--r-- | libs/kstd/kstd/system_error.hpp | 222 | ||||
| -rw-r--r-- | libs/kstd/kstd/unikstd.h | 12 |
3 files changed, 227 insertions, 92 deletions
diff --git a/libs/kstd/kstd/posix.hpp b/libs/kstd/kstd/posix.hpp new file mode 100644 index 00000000..12bd5ec0 --- /dev/null +++ b/libs/kstd/kstd/posix.hpp @@ -0,0 +1,85 @@ +#ifndef KSTD_CERRNO_HPP +#define KSTD_CERRNO_HPP + +namespace kstd::posix +{ + + constexpr auto static inline eafnosupport = 1; + constexpr auto static inline eaddrinuse = 2; + constexpr auto static inline eaddrnotavail = 3; + constexpr auto static inline eisconn = 4; + constexpr auto static inline e2big = 5; + constexpr auto static inline edom = 6; + constexpr auto static inline efault = 7; + constexpr auto static inline ebadf = 8; + constexpr auto static inline ebadmsg = 9; + constexpr auto static inline epipe = 10; + constexpr auto static inline econnaborted = 11; + constexpr auto static inline ealready = 12; + constexpr auto static inline econnrefused = 13; + constexpr auto static inline econnreset = 14; + constexpr auto static inline exdev = 15; + constexpr auto static inline edestaddrreq = 16; + constexpr auto static inline ebusy = 17; + constexpr auto static inline enotempty = 18; + constexpr auto static inline enoexec = 19; + constexpr auto static inline eexist = 20; + constexpr auto static inline efbig = 21; + constexpr auto static inline enametoolong = 22; + constexpr auto static inline enosys = 23; + constexpr auto static inline ehostunreach = 24; + constexpr auto static inline eidrm = 25; + constexpr auto static inline eilseq = 26; + constexpr auto static inline enotty = 27; + constexpr auto static inline eintr = 28; + constexpr auto static inline einval = 29; + constexpr auto static inline espipe = 30; + constexpr auto static inline eio = 31; + constexpr auto static inline eisdir = 32; + constexpr auto static inline emsgsize = 33; + constexpr auto static inline enetdown = 34; + constexpr auto static inline enetreset = 35; + constexpr auto static inline enetunreach = 36; + constexpr auto static inline enobufs = 37; + constexpr auto static inline echild = 38; + constexpr auto static inline enolink = 39; + constexpr auto static inline enolck = 40; + constexpr auto static inline enomsg = 41; + constexpr auto static inline enoprotoopt = 42; + constexpr auto static inline enospc = 43; + constexpr auto static inline enodev = 44; + constexpr auto static inline enxio = 45; + constexpr auto static inline enoent = 46; + constexpr auto static inline esrch = 47; + constexpr auto static inline enotdir = 48; + constexpr auto static inline enotsock = 49; + constexpr auto static inline enotconn = 50; + constexpr auto static inline enomem = 51; + constexpr auto static inline enotsup = 52; + constexpr auto static inline ecanceled = 53; + constexpr auto static inline einprogress = 54; + constexpr auto static inline eperm = 55; + constexpr auto static inline eopnotsupp = 56; + constexpr auto static inline ewouldblock = 57; + constexpr auto static inline eownerdead = 58; + constexpr auto static inline eacces = 59; + constexpr auto static inline eproto = 60; + constexpr auto static inline eprotonosupport = 61; + constexpr auto static inline erofs = 62; + constexpr auto static inline edeadlk = 63; + constexpr auto static inline eagain = 64; + constexpr auto static inline erange = 65; + constexpr auto static inline esocktnosupport = 66; + constexpr auto static inline enotrecoverable = 67; + constexpr auto static inline etxtbsy = 68; + constexpr auto static inline etimedout = 69; + constexpr auto static inline emfile = 70; + constexpr auto static inline enfile = 71; + constexpr auto static inline emlink = 72; + constexpr auto static inline eloop = 73; + constexpr auto static inline eoverflow = 74; + constexpr auto static inline eprototype = 75; + +} // namespace kstd::posix + +#endif
\ No newline at end of file diff --git a/libs/kstd/kstd/system_error.hpp b/libs/kstd/kstd/system_error.hpp index 2f1e38bf..77d85172 100644 --- a/libs/kstd/kstd/system_error.hpp +++ b/libs/kstd/kstd/system_error.hpp @@ -2,6 +2,7 @@ #define KSTD_SYSTEM_ERROR_HPP #include <kstd/format.hpp> +#include <kstd/posix.hpp> // IWYU pragma: export #include <compare> #include <cstdint> @@ -15,30 +16,74 @@ namespace kstd struct error_condition; struct error_code; + //! Determine if a given enumeration type is an error condition enumeration. + //! + //! An enumeration type is an error condition enumeration if it defines generic, system-level error conditions. + //! Specific subsystem error enumerations on the other hand are not generic enough to be considered error conditions + //! and are thus called error codes. + //! + //! @note Types may opt in to being an error condition enumeration by specializing this class template. + //! + //! @tparam CandidateType The type to check. template<typename CandidateType> requires(std::is_enum_v<CandidateType>) struct is_error_condition_enum : std::false_type { }; + //! Determine if a given enumeration type is an error condition enumeration. + //! + //! @see is_error_condition_enum + //! + //! @tparam CandidateType The type to check. template<typename CandidateType> constexpr auto inline is_error_condition_enum_v = is_error_condition_enum<CandidateType>::value; + //! Determine if a given enumeration type is an error condition enumeration. + //! + //! @see is_error_condition_enum + //! @tparam CandidateType The type to check. template<typename CandidateType> concept error_condition_enum = std::is_enum_v<CandidateType> && is_error_condition_enum_v<CandidateType>; + //! Determine if a given enumeration type is an error code enumeration. + //! + //! An enumeration type is an error code enumeration if it defines specific, subsystem-level error codes. + //! Generic error conditions are not specific enough to be considered error codes and are thus called error + //! conditions. + //! + //! @note Types may opt in to being an error code enumeration by specializing this class template. + //! + //! @tparam CandidateType The type to check. template<typename CandidateType> requires(std::is_enum_v<CandidateType>) struct is_error_code_enum : std::false_type { }; + //! Determine if a given enumeration type is an error code enumeration. + //! + //! @see is_error_code_enum + //! + //! @tparam CandidateType The type to check. template<typename CandidateType> constexpr auto inline is_error_code_enum_v = is_error_code_enum<CandidateType>::value; + //! Determine if a given enumeration type is an error code enumeration. + //! + //! @see is_error_code_enum + //! + //! @tparam CandidateType The type to check. template<typename CandidateType> concept error_code_enum = std::is_enum_v<CandidateType> && is_error_code_enum_v<CandidateType>; + //! A category of error codes or conditions. + //! + //! An error category is a group of related error codes or conditions. Each error code or condition belongs to exactly + //! one error category. Error categories are used to provide additional context and information about the error codes + //! or conditions they contain. They can also be used to compare error codes or conditions from different categories. + //! + //! Subsystems shall defined their own error categories for their error codes, by inheriting from this class. struct error_category { constexpr error_category() noexcept = default; @@ -49,21 +94,42 @@ namespace kstd auto operator=(error_category const &) -> error_category & = delete; + //! Get the name of this error category. [[nodiscard]] constexpr auto virtual name() const noexcept -> std::string_view = 0; + //! Get the default error condition for a given error code value in this category. + //! + //! @param value The error code value to get the default error condition for. + //! @return The default error condition for the given error code value in this category. [[nodiscard]] constexpr auto virtual default_error_condition(int value) const noexcept -> error_condition; + //! Check if a given error code value is equivalent to a given error condition in this category. + //! + //! @param value The error code value to check. + //! @param other The error condition to compare against. + //! @return True if the error code value is equivalent to the error condition in this category, false otherwise. [[nodiscard]] constexpr auto virtual equivalent(int value, error_condition const & other) const noexcept -> bool; - [[nodiscard]] constexpr auto virtual equivalent(error_code const &, int condition) const noexcept -> bool; - + //! Check if a given error code is equivalent to a given error condition in this category. + //! + //! @param code The error code to check. + //! @param condition The error condition to compare against. + //! @return True if the error code is equivalent to the error condition in this category, false otherwise. + [[nodiscard]] constexpr auto virtual equivalent(error_code const & code, int condition) const noexcept -> bool; + + //! Get the message for a given error code value in this category. + //! + //! @param value The error code value to get the message for. + //! @return The message for the given error code value in this category. [[nodiscard]] constexpr auto virtual message(int value) const noexcept -> std::string_view = 0; + //! Check if this error category is equal to another one. [[nodiscard]] constexpr auto operator==(error_category const & other) const noexcept -> bool { return this == &other; } + //! Lexicographically compare this error category to a different one. [[nodiscard]] constexpr auto operator<=>(error_category const & other) const noexcept -> std::strong_ordering { return std::compare_three_way{}(this, &other); @@ -216,82 +282,80 @@ namespace kstd enum struct errc : std::uint32_t { - success, - address_family_not_supported, - address_in_use, - address_not_available, - already_connected, - argument_list_too_long, - argument_out_of_domain, - bad_address, - bad_file_descriptor, - bad_message, - broken_pipe, - connection_aborted, - connection_already_in_progress, - connection_refused, - connection_reset, - cross_device_link, - destination_address_required, - device_or_resource_busy, - directory_not_empty, - executable_format_error, - file_exists, - file_too_large, - filename_too_long, - function_not_supported, - host_unreachable, - identifier_removed, - illegal_byte_sequence, - inappropriate_io_control_operation, - interrupted, - invalid_argument, - invalid_seek, - io_error, - is_a_directory, - message_size, - network_down, - network_reset, - network_unreachable, - no_buffer_space, - no_child_process, - no_link, - no_lock_available, - no_message, - no_protocol_option, - no_space_on_device, - no_such_device, - no_such_device_or_address, - no_such_file_or_directory, - no_such_process, - not_a_directory, - not_a_socket, - not_connected, - not_enough_memory, - not_supported, - operation_canceled, - operation_in_progress, - operation_not_permitted, - operation_not_supported, - operation_would_block, - owner_dead, - permission_denied, - protocol_error, - protocol_not_supported, - read_only_file_system, - resource_deadlock_would_occur, - resource_unavailable_try_again, - result_out_of_range, - socket_type_not_supported, - state_not_recoverable, - text_file_busy, - timed_out, - too_many_files_open, - too_many_files_open_in_system, - too_many_links, - too_many_symbolic_link_levels, - value_too_large, - wrong_protocol_type, + address_family_not_supported = posix::eafnosupport, + address_in_use = posix::eaddrinuse, + address_not_available = posix::eaddrnotavail, + already_connected = posix::eisconn, + argument_list_too_long = posix::e2big, + argument_out_of_domain = posix::edom, + bad_address = posix::efault, + bad_file_descriptor = posix::ebadf, + bad_message = posix::ebadmsg, + broken_pipe = posix::epipe, + connection_aborted = posix::econnaborted, + connection_already_in_progress = posix::ealready, + connection_refused = posix::econnrefused, + connection_reset = posix::econnreset, + cross_device_link = posix::exdev, + destination_address_required = posix::edestaddrreq, + device_or_resource_busy = posix::ebusy, + directory_not_empty = posix::enotempty, + executable_format_error = posix::enoexec, + file_exists = posix::eexist, + file_too_large = posix::efbig, + filename_too_long = posix::enametoolong, + function_not_supported = posix::enosys, + host_unreachable = posix::ehostunreach, + identifier_removed = posix::eidrm, + illegal_byte_sequence = posix::eilseq, + inappropriate_io_control_operation = posix::enotty, + interrupted = posix::eintr, + invalid_argument = posix::einval, + invalid_seek = posix::espipe, + io_error = posix::eio, + is_a_directory = posix::eisdir, + message_size = posix::emsgsize, + network_down = posix::enetdown, + network_reset = posix::enetreset, + network_unreachable = posix::enetunreach, + no_buffer_space = posix::enobufs, + no_child_process = posix::echild, + no_link = posix::enolink, + no_lock_available = posix::enolck, + no_message = posix::enomsg, + no_protocol_option = posix::enoprotoopt, + no_space_on_device = posix::enospc, + no_such_device_or_address = posix::enxio, + no_such_device = posix::enodev, + no_such_file_or_directory = posix::enoent, + no_such_process = posix::esrch, + not_a_directory = posix::enotdir, + not_a_socket = posix::enotsock, + not_connected = posix::enotconn, + not_enough_memory = posix::enomem, + not_supported = posix::enotsup, + operation_canceled = posix::ecanceled, + operation_in_progress = posix::einprogress, + operation_not_permitted = posix::eperm, + operation_not_supported = posix::eopnotsupp, + operation_would_block = posix::ewouldblock, + owner_dead = posix::eownerdead, + permission_denied = posix::eacces, + protocol_error = posix::eproto, + protocol_not_supported = posix::eprotonosupport, + read_only_file_system = posix::erofs, + resource_deadlock_would_occur = posix::edeadlk, + resource_unavailable_try_again = posix::eagain, + result_out_of_range = posix::erange, + state_not_recoverable = posix::enotrecoverable, + text_file_busy = posix::etxtbsy, + timed_out = posix::etimedout, + too_many_files_open_in_system = posix::enfile, + too_many_files_open = posix::emfile, + too_many_links = posix::emlink, + too_many_symbolic_link_levels = posix::eloop, + value_too_large = posix::eoverflow, + wrong_protocol_type = posix::eprototype, }; template<> @@ -306,7 +370,6 @@ namespace kstd switch (error) { // clang-format off - case errc::success: return "success"; case errc::address_family_not_supported: return "address family not supported"; case errc::address_in_use: return "address in use"; case errc::address_not_available: return "address not available"; @@ -372,7 +435,6 @@ namespace kstd case errc::resource_deadlock_would_occur: return "resource deadlock would occur"; case errc::resource_unavailable_try_again: return "resource unavailable, try again"; case errc::result_out_of_range: return "result out of range"; - case errc::socket_type_not_supported: return "socket type not supported"; case errc::state_not_recoverable: return "state not recoverable"; case errc::text_file_busy: return "text file busy"; case errc::timed_out: return "timed out"; diff --git a/libs/kstd/kstd/unikstd.h b/libs/kstd/kstd/unikstd.h deleted file mode 100644 index aa60be63..00000000 --- a/libs/kstd/kstd/unikstd.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef KSTD_UNIKSTD_HPP -#define KSTD_UNIKSTD_HPP - -#include <cstddef> -#include <type_traits> - -namespace kstd -{ - using ssize_t = std::make_signed_t<std::size_t>; -} // namespace kstd - -#endif
\ No newline at end of file |
