|
| 1 | +#ifdef __COSMOPOLITAN__ |
| 2 | +#include <filesystem> |
| 3 | + |
| 4 | +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM |
| 5 | + |
| 6 | +namespace detail { |
| 7 | + |
| 8 | +std::errc __cosmo_err_to_errc_impl(int err) { |
| 9 | + if (err == EAFNOSUPPORT) return errc::address_family_not_supported; |
| 10 | + if (err == EADDRINUSE) return errc::address_in_use; |
| 11 | + if (err == EADDRNOTAVAIL) return errc::address_not_available; |
| 12 | + if (err == EISCONN) return errc::already_connected; |
| 13 | + if (err == E2BIG) return errc::argument_list_too_long; |
| 14 | + if (err == EDOM) return errc::argument_out_of_domain; |
| 15 | + if (err == EFAULT) return errc::bad_address; |
| 16 | + if (err == EBADF) return errc::bad_file_descriptor; |
| 17 | + if (err == EBADMSG) return errc::bad_message; |
| 18 | + if (err == EPIPE) return errc::broken_pipe; |
| 19 | + if (err == ECONNABORTED) return errc::connection_aborted; |
| 20 | + if (err == EALREADY) return errc::connection_already_in_progress; |
| 21 | + if (err == ECONNREFUSED) return errc::connection_refused; |
| 22 | + if (err == ECONNRESET) return errc::connection_reset; |
| 23 | + if (err == EXDEV) return errc::cross_device_link; |
| 24 | + if (err == EDESTADDRREQ) return errc::destination_address_required; |
| 25 | + if (err == EBUSY) return errc::device_or_resource_busy; |
| 26 | + if (err == ENOTEMPTY) return errc::directory_not_empty; |
| 27 | + if (err == ENOEXEC) return errc::executable_format_error; |
| 28 | + if (err == EEXIST) return errc::file_exists; |
| 29 | + if (err == EFBIG) return errc::file_too_large; |
| 30 | + if (err == ENAMETOOLONG) return errc::filename_too_long; |
| 31 | + if (err == ENOSYS) return errc::function_not_supported; |
| 32 | + if (err == EHOSTUNREACH) return errc::host_unreachable; |
| 33 | + if (err == EIDRM) return errc::identifier_removed; |
| 34 | + if (err == EILSEQ) return errc::illegal_byte_sequence; |
| 35 | + if (err == ENOTTY) return errc::inappropriate_io_control_operation; |
| 36 | + if (err == EINTR) return errc::interrupted; |
| 37 | + if (err == EINVAL) return errc::invalid_argument; |
| 38 | + if (err == ESPIPE) return errc::invalid_seek; |
| 39 | + if (err == EIO) return errc::io_error; |
| 40 | + if (err == EISDIR) return errc::is_a_directory; |
| 41 | + if (err == EMSGSIZE) return errc::message_size; |
| 42 | + if (err == ENETDOWN) return errc::network_down; |
| 43 | + if (err == ENETRESET) return errc::network_reset; |
| 44 | + if (err == ENETUNREACH) return errc::network_unreachable; |
| 45 | + if (err == ENOBUFS) return errc::no_buffer_space; |
| 46 | + if (err == ECHILD) return errc::no_child_process; |
| 47 | + if (err == ENOLINK) return errc::no_link; |
| 48 | + if (err == ENOLCK) return errc::no_lock_available; |
| 49 | + if (err == ENOMSG) return errc::no_message; |
| 50 | + if (err == (ENODATA ? ENODATA : ENOMSG)) return errc::no_message_available; |
| 51 | + if (err == ENOPROTOOPT) return errc::no_protocol_option; |
| 52 | + if (err == ENOSPC) return errc::no_space_on_device; |
| 53 | + if (err == ENOMEM) return errc::not_enough_memory; |
| 54 | + if (err == (ENOSR ? ENOSR : ENOMEM)) return errc::no_stream_resources; |
| 55 | + if (err == ENXIO) return errc::no_such_device_or_address; |
| 56 | + if (err == ENODEV) return errc::no_such_device; |
| 57 | + if (err == ENOENT) return errc::no_such_file_or_directory; |
| 58 | + if (err == ESRCH) return errc::no_such_process; |
| 59 | + if (err == ENOTDIR) return errc::not_a_directory; |
| 60 | + if (err == ENOTSOCK) return errc::not_a_socket; |
| 61 | + if (err == (ENOSTR ? ENOSTR : EINVAL)) return errc::not_a_stream; |
| 62 | + if (err == ENOTCONN) return errc::not_connected; |
| 63 | + if (err == ENOTSUP) return errc::not_supported; |
| 64 | + if (err == ECANCELED) return errc::operation_canceled; |
| 65 | + if (err == EINPROGRESS) return errc::operation_in_progress; |
| 66 | + if (err == EPERM) return errc::operation_not_permitted; |
| 67 | + if (err == EOPNOTSUPP) return errc::operation_not_supported; |
| 68 | + if (err == EWOULDBLOCK) return errc::operation_would_block; |
| 69 | + if (err == EOWNERDEAD) return errc::owner_dead; |
| 70 | + if (err == EACCES) return errc::permission_denied; |
| 71 | + if (err == EPROTO) return errc::protocol_error; |
| 72 | + if (err == EPROTONOSUPPORT) return errc::protocol_not_supported; |
| 73 | + if (err == EROFS) return errc::read_only_file_system; |
| 74 | + if (err == EDEADLK) return errc::resource_deadlock_would_occur; |
| 75 | + if (err == EAGAIN) return errc::resource_unavailable_try_again; |
| 76 | + if (err == ERANGE) return errc::result_out_of_range; |
| 77 | + if (err == ENOTRECOVERABLE) return errc::state_not_recoverable; |
| 78 | + if (err == ETIME) return errc::stream_timeout; |
| 79 | + if (err == ETXTBSY) return errc::text_file_busy; |
| 80 | + if (err == ETIMEDOUT) return errc::timed_out; |
| 81 | + if (err == ENFILE) return errc::too_many_files_open_in_system; |
| 82 | + if (err == EMFILE) return errc::too_many_files_open; |
| 83 | + if (err == EMLINK) return errc::too_many_links; |
| 84 | + if (err == ELOOP) return errc::too_many_symbolic_link_levels; |
| 85 | + if (err == EOVERFLOW) return errc::value_too_large; |
| 86 | + if (err == EPROTOTYPE) return errc::wrong_protocol_type; |
| 87 | + return errc::not_supported; |
| 88 | +} |
| 89 | + |
| 90 | +int __cosmo_errc_to_err_impl(std::errc err) { |
| 91 | + if (err == errc::address_family_not_supported) return EAFNOSUPPORT; |
| 92 | + if (err == errc::address_in_use) return EADDRINUSE; |
| 93 | + if (err == errc::address_not_available) return EADDRNOTAVAIL; |
| 94 | + if (err == errc::already_connected) return EISCONN; |
| 95 | + if (err == errc::argument_list_too_long) return E2BIG; |
| 96 | + if (err == errc::argument_out_of_domain) return EDOM; |
| 97 | + if (err == errc::bad_address) return EFAULT; |
| 98 | + if (err == errc::bad_file_descriptor) return EBADF; |
| 99 | + if (err == errc::bad_message) return EBADMSG; |
| 100 | + if (err == errc::broken_pipe) return EPIPE; |
| 101 | + if (err == errc::connection_aborted) return ECONNABORTED; |
| 102 | + if (err == errc::connection_already_in_progress) return EALREADY; |
| 103 | + if (err == errc::connection_refused) return ECONNREFUSED; |
| 104 | + if (err == errc::connection_reset) return ECONNRESET; |
| 105 | + if (err == errc::cross_device_link) return EXDEV; |
| 106 | + if (err == errc::destination_address_required) return EDESTADDRREQ; |
| 107 | + if (err == errc::device_or_resource_busy) return EBUSY; |
| 108 | + if (err == errc::directory_not_empty) return ENOTEMPTY; |
| 109 | + if (err == errc::executable_format_error) return ENOEXEC; |
| 110 | + if (err == errc::file_exists) return EEXIST; |
| 111 | + if (err == errc::file_too_large) return EFBIG; |
| 112 | + if (err == errc::filename_too_long) return ENAMETOOLONG; |
| 113 | + if (err == errc::function_not_supported) return ENOSYS; |
| 114 | + if (err == errc::host_unreachable) return EHOSTUNREACH; |
| 115 | + if (err == errc::identifier_removed) return EIDRM; |
| 116 | + if (err == errc::illegal_byte_sequence) return EILSEQ; |
| 117 | + if (err == errc::inappropriate_io_control_operation) return ENOTTY; |
| 118 | + if (err == errc::interrupted) return EINTR; |
| 119 | + if (err == errc::invalid_argument) return EINVAL; |
| 120 | + if (err == errc::invalid_seek) return ESPIPE; |
| 121 | + if (err == errc::io_error) return EIO; |
| 122 | + if (err == errc::is_a_directory) return EISDIR; |
| 123 | + if (err == errc::message_size) return EMSGSIZE; |
| 124 | + if (err == errc::network_down) return ENETDOWN; |
| 125 | + if (err == errc::network_reset) return ENETRESET; |
| 126 | + if (err == errc::network_unreachable) return ENETUNREACH; |
| 127 | + if (err == errc::no_buffer_space) return ENOBUFS; |
| 128 | + if (err == errc::no_child_process) return ECHILD; |
| 129 | + if (err == errc::no_link) return ENOLINK; |
| 130 | + if (err == errc::no_lock_available) return ENOLCK; |
| 131 | + if (err == errc::no_message) return ENOMSG; |
| 132 | + if (err == errc::no_message_available) return (ENODATA ? ENODATA : ENOMSG); |
| 133 | + if (err == errc::no_protocol_option) return ENOPROTOOPT; |
| 134 | + if (err == errc::no_space_on_device) return ENOSPC; |
| 135 | + if (err == errc::not_enough_memory) return ENOMEM; |
| 136 | + if (err == errc::no_stream_resources) return (ENOSR ? ENOSR : ENOMEM); |
| 137 | + if (err == errc::no_such_device_or_address) return ENXIO; |
| 138 | + if (err == errc::no_such_device) return ENODEV; |
| 139 | + if (err == errc::no_such_file_or_directory) return ENOENT; |
| 140 | + if (err == errc::no_such_process) return ESRCH; |
| 141 | + if (err == errc::not_a_directory) return ENOTDIR; |
| 142 | + if (err == errc::not_a_socket) return ENOTSOCK; |
| 143 | + if (err == errc::not_a_stream) return (ENOSTR ? ENOSTR : EINVAL); |
| 144 | + if (err == errc::not_connected) return ENOTCONN; |
| 145 | + if (err == errc::not_supported) return ENOTSUP; |
| 146 | + if (err == errc::operation_canceled) return ECANCELED; |
| 147 | + if (err == errc::operation_in_progress) return EINPROGRESS; |
| 148 | + if (err == errc::operation_not_permitted) return EPERM; |
| 149 | + if (err == errc::operation_not_supported) return EOPNOTSUPP; |
| 150 | + if (err == errc::operation_would_block) return EWOULDBLOCK; |
| 151 | + if (err == errc::owner_dead) return EOWNERDEAD; |
| 152 | + if (err == errc::permission_denied) return EACCES; |
| 153 | + if (err == errc::protocol_error) return EPROTO; |
| 154 | + if (err == errc::protocol_not_supported) return EPROTONOSUPPORT; |
| 155 | + if (err == errc::read_only_file_system) return EROFS; |
| 156 | + if (err == errc::resource_deadlock_would_occur) return EDEADLK; |
| 157 | + if (err == errc::resource_unavailable_try_again) return EAGAIN; |
| 158 | + if (err == errc::result_out_of_range) return ERANGE; |
| 159 | + if (err == errc::state_not_recoverable) return ENOTRECOVERABLE; |
| 160 | + if (err == errc::stream_timeout) return ETIME; |
| 161 | + if (err == errc::text_file_busy) return ETXTBSY; |
| 162 | + if (err == errc::timed_out) return ETIMEDOUT; |
| 163 | + if (err == errc::too_many_files_open_in_system) return ENFILE; |
| 164 | + if (err == errc::too_many_files_open) return EMFILE; |
| 165 | + if (err == errc::too_many_links) return EMLINK; |
| 166 | + if (err == errc::too_many_symbolic_link_levels) return ELOOP; |
| 167 | + if (err == errc::value_too_large) return EOVERFLOW; |
| 168 | + if (err == errc::wrong_protocol_type) return EPROTOTYPE; |
| 169 | + return ENOTSUP; |
| 170 | +} |
| 171 | + |
| 172 | +std::errc __cosmo_err_to_errc(int err) { |
| 173 | + if (err >= 65536) |
| 174 | + return (std::errc)err; |
| 175 | + return __cosmo_err_to_errc_impl(err); |
| 176 | +} |
| 177 | + |
| 178 | +int __cosmo_errc_to_err(std::errc err) { |
| 179 | + if ((int)err < 65536) |
| 180 | + return (int)err; |
| 181 | + return __cosmo_errc_to_err_impl(err); |
| 182 | +} |
| 183 | + |
| 184 | +} // end namespace detail |
| 185 | + |
| 186 | +_LIBCPP_END_NAMESPACE_FILESYSTEM |
| 187 | + |
| 188 | +#endif // __COSMOPOLITAN__ |
0 commit comments