use _dupenv_s, strerror_s and strerror_r
This commit is contained in:
parent
adfee27b59
commit
e04a2db825
2 changed files with 22 additions and 3 deletions
|
@ -49,7 +49,14 @@ Node::Node(const std::string & node_name, context::Context::SharedPtr context)
|
|||
number_of_subscriptions_(0), number_of_timers_(0), number_of_services_(0)
|
||||
{
|
||||
size_t domain_id = 0;
|
||||
char * ros_domain_id = getenv("ROS_DOMAIN_ID");
|
||||
char * ros_domain_id = nullptr;
|
||||
const char * env_var = "ROS_DOMAIN_ID";
|
||||
#ifndef _WIN32
|
||||
getenv(env_var);
|
||||
#else
|
||||
size_t ros_domain_id_size;
|
||||
_dupenv_s(&ros_domain_id, &ros_domain_id_size, env_var);
|
||||
#endif
|
||||
if (ros_domain_id) {
|
||||
unsigned long number = strtoul(ros_domain_id, NULL, 0);
|
||||
if (number == (std::numeric_limits<unsigned long>::max)()) {
|
||||
|
@ -57,6 +64,11 @@ Node::Node(const std::string & node_name, context::Context::SharedPtr context)
|
|||
}
|
||||
domain_id = static_cast<size_t>(number);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (ros_domain_id) {
|
||||
free(ros_domain_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto node = rmw_create_node(name_.c_str(), domain_id);
|
||||
if (!node) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
#include <rmw/macros.h>
|
||||
|
@ -121,11 +122,17 @@ init(int argc, char * argv[])
|
|||
if (::old_signal_handler == SIG_ERR)
|
||||
#endif
|
||||
{
|
||||
const size_t error_length = 1024;
|
||||
char error_string[error_length];
|
||||
#ifndef _WIN32
|
||||
strerror_r(errno, error_string, error_length);
|
||||
#else
|
||||
strerror_s(error_string, error_length, errno);
|
||||
#endif
|
||||
// *INDENT-OFF*
|
||||
throw std::runtime_error(
|
||||
std::string("Failed to set SIGINT signal handler: (" + std::to_string(errno) + ")") +
|
||||
// TODO(wjwwood): use strerror_r on POSIX and strerror_s on Windows.
|
||||
std::strerror(errno));
|
||||
error_string);
|
||||
// *INDENT-ON*
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue