Merge pull request #168 from ros2/avoid_compiler_warning
Avoid unused return value warning
This commit is contained in:
commit
67dcd9fe49
1 changed files with 12 additions and 1 deletions
|
@ -117,7 +117,18 @@ rclcpp::utilities::init(int argc, char * argv[])
|
||||||
// NOLINTNEXTLINE(runtime/arrays)
|
// NOLINTNEXTLINE(runtime/arrays)
|
||||||
char error_string[error_length];
|
char error_string[error_length];
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
strerror_r(errno, error_string, error_length);
|
#ifdef _GNU_SOURCE
|
||||||
|
char * msg = strerror_r(errno, error_string, error_length);
|
||||||
|
if (msg != error_string) {
|
||||||
|
strncpy(error_string, msg, error_length);
|
||||||
|
msg[error_length - 1] = '\0';
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int error_status = strerror_r(errno, error_string, error_length);
|
||||||
|
if (error_status != 0) {
|
||||||
|
throw std::runtime_error("Failed to get error string for errno: " + std::to_string(errno));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
strerror_s(error_string, error_length, errno);
|
strerror_s(error_string, error_length, errno);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue