diff --git a/include/rcutils/macros.h b/include/rcutils/macros.h index c18d36ea..6dad0842 100644 --- a/include/rcutils/macros.h +++ b/include/rcutils/macros.h @@ -22,11 +22,11 @@ extern "C" { #endif -#ifndef _WIN32 +#ifndef _MSC_VER /// A macro to make the compiler warn when the return value of a function is not used. #define RCUTILS_WARN_UNUSED __attribute__((warn_unused_result)) #else -/// A macro to make the compiler warn when the return value of a function is not used. +/// A macro to make the compiler (MSVC) warn when the return value of a function is not used. #define RCUTILS_WARN_UNUSED _Check_return_ #endif diff --git a/include/rcutils/stdatomic_helper.h b/include/rcutils/stdatomic_helper.h index 2c39e71d..58811f14 100644 --- a/include/rcutils/stdatomic_helper.h +++ b/include/rcutils/stdatomic_helper.h @@ -27,7 +27,7 @@ # endif #endif -#if !defined(_WIN32) +#if !defined(_WIN32) || defined(__MINGW64__) // The my__has_feature avoids a preprocessor error when you check for it and // use it on the same line below. diff --git a/src/process.c b/src/process.c index 9f21bbf7..b93ed9f7 100644 --- a/src/process.c +++ b/src/process.c @@ -60,7 +60,7 @@ char * rcutils_get_executable_name(rcutils_allocator_t allocator) #if defined __APPLE__ || defined __FreeBSD__ || (defined __ANDROID__ && __ANDROID_API__ >= 21) const char * appname = getprogname(); -#elif defined __GNUC__ && !defined(__QNXNTO__) && !defined(__OHOS__) +#elif (defined __GNUC__ && !defined(__MINGW64__)) && !defined(__QNXNTO__) && !defined(__OHOS__) const char * appname = program_invocation_name; #elif defined _WIN32 || defined __CYGWIN__ char appname[MAX_PATH]; @@ -85,7 +85,7 @@ char * rcutils_get_executable_name(rcutils_allocator_t allocator) } // Get just the executable name (Unix may return the absolute path) -#if defined __APPLE__ || defined __FreeBSD__ || defined __GNUC__ +#if defined __APPLE__ || defined __FreeBSD__ || (defined __GNUC__ && !defined(__MINGW64__)) // We need an intermediate copy because basename may modify its arguments char * intermediate = rcutils_strdup(appname, allocator); if (NULL == intermediate) { diff --git a/test/test_process.cpp b/test/test_process.cpp index cbec8352..ecf17909 100644 --- a/test/test_process.cpp +++ b/test/test_process.cpp @@ -33,7 +33,7 @@ TEST(TestProcess, test_get_executable_name) { EXPECT_STREQ(NULL, rcutils_get_executable_name(time_bomb_allocator)); // Allocating intermediate fails. This allocation doesn't happen on windows -#if defined __APPLE__ || defined __FreeBSD__ || defined __GNUC__ +#if defined __APPLE__ || defined __FreeBSD__ || (defined __GNUC__ && !defined(__MINGW64__)) set_time_bomb_allocator_malloc_count(time_bomb_allocator, 1); EXPECT_STREQ(NULL, rcutils_get_executable_name(time_bomb_allocator)); #endif