diff --git a/platforms/posix/include/windows_shim/afunix.h b/platforms/posix/include/windows_shim/afunix.h index e893b2a6e3..d4371bd14b 100644 --- a/platforms/posix/include/windows_shim/afunix.h +++ b/platforms/posix/include/windows_shim/afunix.h @@ -43,9 +43,7 @@ */ #pragma once -#ifndef _WIN32 -# error "afunix.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include #include @@ -114,3 +112,5 @@ typedef struct sockaddr_un sockaddr_un; #ifdef __cplusplus } #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/arpa/inet.h b/platforms/posix/include/windows_shim/arpa/inet.h index 83261cf53e..3f207c7946 100644 --- a/platforms/posix/include/windows_shim/arpa/inet.h +++ b/platforms/posix/include/windows_shim/arpa/inet.h @@ -40,9 +40,7 @@ */ #pragma once -#ifndef _WIN32 -# error "arpa/inet.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include @@ -73,3 +71,5 @@ struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host); #ifdef __cplusplus } #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/libgen.h b/platforms/posix/include/windows_shim/libgen.h index b4c9e985e9..2e1f23b3b0 100644 --- a/platforms/posix/include/windows_shim/libgen.h +++ b/platforms/posix/include/windows_shim/libgen.h @@ -38,6 +38,8 @@ #pragma once +#ifdef _WIN32 + #include #ifdef __cplusplus @@ -79,7 +81,7 @@ static inline char *dirname(char *path) return (char *)"."; } - char *last = NULL; + char *last = nullptr; for (char *p = path; *p; ++p) { if (*p == '/' || *p == '\\') { @@ -103,3 +105,5 @@ static inline char *dirname(char *path) #ifdef __cplusplus } #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/net/if.h b/platforms/posix/include/windows_shim/net/if.h index 0f1c10d1af..4eb00dfa28 100644 --- a/platforms/posix/include/windows_shim/net/if.h +++ b/platforms/posix/include/windows_shim/net/if.h @@ -41,9 +41,7 @@ */ #pragma once -#ifndef _WIN32 -# error "net/if.h shim only valid on Windows" -#endif +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -241,3 +239,5 @@ void if_freenameindex(struct if_nameindex *ptr); #ifdef __cplusplus } #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/netdb.h b/platforms/posix/include/windows_shim/netdb.h index 4a1208a4e1..1cf3356413 100644 --- a/platforms/posix/include/windows_shim/netdb.h +++ b/platforms/posix/include/windows_shim/netdb.h @@ -42,9 +42,7 @@ */ #pragma once -#ifndef _WIN32 -# error "netdb.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include @@ -164,3 +162,5 @@ struct servent *getservent(void); #ifdef __cplusplus } #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/netinet/in.h b/platforms/posix/include/windows_shim/netinet/in.h index f0e7631a2a..bfea4ff138 100644 --- a/platforms/posix/include/windows_shim/netinet/in.h +++ b/platforms/posix/include/windows_shim/netinet/in.h @@ -40,9 +40,7 @@ */ #pragma once -#ifndef _WIN32 -# error "netinet/in.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include @@ -91,3 +89,5 @@ typedef uint16_t in_port_t; #ifndef IN6_ARE_ADDR_EQUAL #define IN6_ARE_ADDR_EQUAL(a, b) IN6_ADDR_EQUAL((a), (b)) #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/netinet/tcp.h b/platforms/posix/include/windows_shim/netinet/tcp.h index 47d30c042c..0b726fabf2 100644 --- a/platforms/posix/include/windows_shim/netinet/tcp.h +++ b/platforms/posix/include/windows_shim/netinet/tcp.h @@ -39,9 +39,7 @@ */ #pragma once -#ifndef _WIN32 -# error "netinet/tcp.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include #include @@ -70,3 +68,5 @@ #ifndef TCP_USER_TIMEOUT #define TCP_USER_TIMEOUT 18 #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/netinet/udp.h b/platforms/posix/include/windows_shim/netinet/udp.h index 3d2c355bac..b2157a485d 100644 --- a/platforms/posix/include/windows_shim/netinet/udp.h +++ b/platforms/posix/include/windows_shim/netinet/udp.h @@ -38,12 +38,12 @@ */ #pragma once -#ifndef _WIN32 -# error "netinet/udp.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include #ifndef SOL_UDP #define SOL_UDP IPPROTO_UDP #endif + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/sys/types.h b/platforms/posix/include/windows_shim/sys/types.h index 289a3cfaf7..77aacf4c7e 100644 --- a/platforms/posix/include/windows_shim/sys/types.h +++ b/platforms/posix/include/windows_shim/sys/types.h @@ -78,6 +78,7 @@ typedef unsigned int useconds_t; #include_next #endif +#ifdef _WIN32 #ifndef _PX4_SYS_TYPES_ALIASES_DEFINED #define _PX4_SYS_TYPES_ALIASES_DEFINED /** @name BSD/GNU scalar aliases @@ -99,3 +100,4 @@ typedef long long quad_t; typedef unsigned long long u_quad_t; /** @} */ #endif +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/sys/un.h b/platforms/posix/include/windows_shim/sys/un.h index 0f2f870a4d..7b57c95ceb 100644 --- a/platforms/posix/include/windows_shim/sys/un.h +++ b/platforms/posix/include/windows_shim/sys/un.h @@ -42,9 +42,7 @@ */ #pragma once -#ifndef _WIN32 -# error "sys/un.h shim only valid on Windows" -#endif +#ifdef _WIN32 #include #include @@ -64,3 +62,5 @@ typedef struct sockaddr_un sockaddr_un; /* afunix.h already provides struct sockaddr_un. Re-export sun_path/sun_family * aliases if any translation unit expects them. afunix.h on Windows already * names them that way, so no further work is needed. */ + +#endif /* _WIN32 */ diff --git a/platforms/posix/include/windows_shim/time.h b/platforms/posix/include/windows_shim/time.h index 4388b5a201..22eff8bb8d 100644 --- a/platforms/posix/include/windows_shim/time.h +++ b/platforms/posix/include/windows_shim/time.h @@ -40,6 +40,8 @@ */ #pragma once +#ifdef _WIN32 + #if defined(_MSC_VER) && !defined(__clang__) #if defined(__has_include) # if __has_include(<../ucrt/time.h>) @@ -104,30 +106,30 @@ int nanosleep(const struct timespec *req, struct timespec *rem); /** @brief Thread-safe UTC conversion using the Windows gmtime_s() order. */ static inline struct tm *gmtime_r(const time_t *timep, struct tm *result) { - if (!timep || !result) { return NULL; } - return (gmtime_s(result, timep) == 0) ? result : NULL; + if (!timep || !result) { return nullptr; } + return (gmtime_s(result, timep) == 0) ? result : nullptr; } /** @brief Thread-safe local-time conversion using the Windows localtime_s(). */ static inline struct tm *localtime_r(const time_t *timep, struct tm *result) { - if (!timep || !result) { return NULL; } - return (localtime_s(result, timep) == 0) ? result : NULL; + if (!timep || !result) { return nullptr; } + return (localtime_s(result, timep) == 0) ? result : nullptr; } /** @brief Thread-safe asctime() wrapper; @p buf must hold at least 26 bytes. */ static inline char *asctime_r(const struct tm *tm, char *buf) { - if (!tm || !buf) { return NULL; } + if (!tm || !buf) { return nullptr; } /* POSIX requires a 26-byte buffer; match that to asctime_s. */ - return (asctime_s(buf, 26, tm) == 0) ? buf : NULL; + return (asctime_s(buf, 26, tm) == 0) ? buf : nullptr; } /** @brief Thread-safe ctime() wrapper; @p buf must hold at least 26 bytes. */ static inline char *ctime_r(const time_t *timep, char *buf) { - if (!timep || !buf) { return NULL; } - return (ctime_s(buf, 26, timep) == 0) ? buf : NULL; + if (!timep || !buf) { return nullptr; } + return (ctime_s(buf, 26, timep) == 0) ? buf : nullptr; } #ifndef timerisset @@ -167,3 +169,5 @@ static inline char *ctime_r(const time_t *timep, char *buf) #endif #endif /* _PX4_TIME_R_SHIM_DEFINED */ + +#endif /* _WIN32 */ diff --git a/platforms/posix/src/px4/windows/include/px4_windows_internal.h b/platforms/posix/src/px4/windows/include/px4_windows_internal.h index d19686d95c..1b2c384e9c 100644 --- a/platforms/posix/src/px4/windows/include/px4_windows_internal.h +++ b/platforms/posix/src/px4/windows/include/px4_windows_internal.h @@ -49,9 +49,7 @@ */ #pragma once -#ifndef _WIN32 -# error "px4_windows_internal.h is Windows-only" -#endif +#ifdef _WIN32 #define _WIN32_WINNT 0x0A00 #include @@ -110,3 +108,5 @@ int px4_wsa_error_to_errno(int err); * @return Static, human-readable error string. */ const char *px4_hstrerror_text(int err); + +#endif /* _WIN32 */