diff --git a/include/restc-cpp/test_helper.h b/include/restc-cpp/test_helper.h index 2cdf860..a8890e7 100644 --- a/include/restc-cpp/test_helper.h +++ b/include/restc-cpp/test_helper.h @@ -14,10 +14,28 @@ namespace restc_cpp { // Substitute localhost with whatever is in the environment-variable // RESTC_CPP_TEST_DOCKER_ADDRESS inline std::string GetDockerUrl(std::string url) { - const char *docker_addr = std::getenv("RESTC_CPP_TEST_DOCKER_ADDRESS"); + const char* docker_addr = nullptr; + +#ifdef _WIN32 + // On Windows, use _dupenv_s to safely retrieve the environment variable + size_t len = 0; + errno_t err = _dupenv_s(&docker_addr, &len, "RESTC_CPP_TEST_DOCKER_ADDRESS"); + if (err != 0 || docker_addr == nullptr) { + docker_addr = nullptr; // Ensure docker_addr is nullptr if the variable isn't set + } +#else + // On Linux/macOS, use std::getenv + docker_addr = std::getenv("RESTC_CPP_TEST_DOCKER_ADDRESS"); +#endif + if (docker_addr) { boost::replace_all(url, "localhost", docker_addr); +#ifdef _WIN32 + // Free the allocated memory on Windows + free(docker_addr); +#endif } + return url; } diff --git a/src/RequestBodyFileImpl.cpp b/src/RequestBodyFileImpl.cpp index dcd0de3..7f20a2c 100644 --- a/src/RequestBodyFileImpl.cpp +++ b/src/RequestBodyFileImpl.cpp @@ -46,7 +46,7 @@ class RequestBodyFileImpl : public RequestBody if (read_this_time == 0) { const auto err = errno; throw IoException(string{"file read failed: "} - + to_string(err) + " " + strerror(err)); + + to_string(err) + " " + std::system_category().message(err)); } bytes_read_ += read_this_time;