Fix std::filesystem

This change makes a second pass, at fixing the errno issue with libcxx's
filesystem code. Previously, 89.01% of LLVM's test suite was passing and
now 98.59% of their tests pass. Best of all, it's now possible for Clang
to be built as a working APE binary that can to compile the Cosmopolitan
repository. Please note it has only been vetted so far for some objects,
and more work would obviously need to be done in cosmo, to fix warnings.
This commit is contained in:
Justine Tunney 2024-07-28 17:25:20 -07:00
parent 0d7c272d3f
commit 77d3a07ff2
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
14 changed files with 408 additions and 69 deletions

View file

@ -16,6 +16,7 @@
#include <string.h>
#include <string>
#include <system_error>
#include <__system_error/errc.h>
#include "config_elast.h"
@ -23,10 +24,6 @@
# include <android/api-level.h>
#endif
#ifdef __COSMOPOLITAN__
#include <fs/error.h>
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
@ -39,9 +36,7 @@ string do_strerror_r(int ev);
# if defined(_LIBCPP_MSVCRT_LIKE)
string do_strerror_r(int ev) {
#ifdef __COSMOPOLITAN__
ev = (int)filesystem::detail::__cosmo_errc_to_err(ev);
#endif
ev = __errc_to_err(ev);
char buffer[strerror_buff_size];
if (::strerror_s(buffer, strerror_buff_size, ev) == 0)
return string(buffer);
@ -88,9 +83,7 @@ string do_strerror_r(int ev) {
// Preserve errno around the call. (The C++ standard requires that
// system_error functions not modify errno).
const int old_errno = errno;
#ifdef __COSMOPOLITAN__
ev = filesystem::detail::__cosmo_errc_to_err((errc)ev);
#endif
ev = __errc_to_err((errc)ev);
const char* error_message = handle_strerror_r_return(::strerror_r(ev, buffer, strerror_buff_size), buffer);
// If we didn't get any message, print one now.
if (!error_message[0]) {
@ -139,9 +132,7 @@ public:
const char* __generic_error_category::name() const noexcept { return "generic"; }
string __generic_error_category::message(int ev) const {
#ifdef __COSMOPOLITAN__
ev = filesystem::detail::__cosmo_errc_to_err((errc)ev);
#endif
ev = __errc_to_err((errc)ev);
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return string("unspecified generic_category error");
@ -169,9 +160,7 @@ public:
const char* __system_error_category::name() const noexcept { return "system"; }
string __system_error_category::message(int ev) const {
#ifdef __COSMOPOLITAN__
ev = filesystem::detail::__cosmo_errc_to_err((errc)ev);
#endif
ev = __errc_to_err((errc)ev);
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return string("unspecified system_category error");
@ -180,9 +169,7 @@ string __system_error_category::message(int ev) const {
}
error_condition __system_error_category::default_error_condition(int ev) const noexcept {
#ifdef __COSMOPOLITAN__
ev = filesystem::detail::__cosmo_errc_to_err((errc)ev);
#endif
ev = __errc_to_err((errc)ev);
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return error_condition(ev, system_category());
@ -231,11 +218,7 @@ system_error::~system_error() noexcept {}
void __throw_system_error(int ev, const char* what_arg) {
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
#ifdef __COSMOPOLITAN__
std::__throw_system_error(error_code((int)filesystem::detail::__cosmo_err_to_errc(ev), system_category()), what_arg);
#else
std::__throw_system_error(error_code(ev, system_category()), what_arg);
#endif
std::__throw_system_error(error_code((int)__err_to_errc(ev), system_category()), what_arg);
#else
// The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily.
_LIBCPP_VERBOSE_ABORT(