Skip to content

Commit

Permalink
refactor: remove std::filesystem use from libcartesi (unsupported by …
Browse files Browse the repository at this point in the history
…WASI)
  • Loading branch information
edubart committed Nov 6, 2023
1 parent 7043b8c commit 2a32fcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ SOLDFLAGS_Linux:=-shared -fPIC -pthread
CC_Linux=gcc
CXX_Linux=g++
INCS_Linux=
FS_LIB_Linux=-lstdc++fs
PTHREAD_LIB_Linux:=-lpthread
BOOST_INC_Linux:=
GRPC_INC_Linux:=$(shell pkg-config --cflags-only-I grpc++)
Expand Down
3 changes: 0 additions & 3 deletions src/machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <any>
#include <cstring>
#include <exception>
#include <filesystem>
#include <future>
#include <ios>
#include <optional>
Expand Down Expand Up @@ -84,8 +83,6 @@ int cm_result_failure(char **err_msg) try { throw; } catch (std::exception &e) {
return CM_ERROR_REGEX_ERROR;
} catch (std::ios_base::failure &ex) {
return CM_ERROR_SYSTEM_IOS_BASE_FAILURE;
} catch (std::filesystem::filesystem_error &ex) {
return CM_ERROR_FILESYSTEM_ERROR;
} catch (std::runtime_error &ex) {
return CM_ERROR_RUNTIME_ERROR;
} catch (std::bad_typeid &ex) {
Expand Down
15 changes: 10 additions & 5 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <future>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -367,13 +366,19 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) :
const std::string flash_description = "flash drive "s + std::to_string(i++);
// Auto detect flash drive image length
if (f.length == UINT64_C(-1)) {
std::error_code ec;
f.length = std::filesystem::file_size(f.image_filename, ec);
if (ec) {
throw std::system_error{ec.value(), ec.category(),
auto fp = unique_fopen(f.image_filename.c_str(), "rb");
if (fseek(fp.get(), 0, SEEK_END) != 0) {
throw std::system_error{errno, std::generic_category(),
"unable to obtain length of image file '"s + f.image_filename + "' when initializing "s +
flash_description};
}
const auto length = ftell(fp.get());
if (length < 0) {
throw std::system_error{errno, std::generic_category(),
"unable to obtain length of image file '"s + f.image_filename + "' when initializing "s +
flash_description};
}
f.length = length;
}
register_pma_entry(make_flash_drive_pma_entry(flash_description, f));
}
Expand Down

0 comments on commit 2a32fcd

Please sign in to comment.