diff --git a/src/Makefile b/src/Makefile index 845d822ad..af2e5ee25 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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++) diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index 60db702ac..e8ee48be7 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -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) { diff --git a/src/machine.cpp b/src/machine.cpp index a1d811446..bf0fa4ea3 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -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)); }