From c64195e4293d205bd0349c1de78bcbae693e0b13 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 19 Feb 2022 09:59:06 -0800 Subject: [PATCH] cgraph: [nfc] guard 'strcasecmp' definition to avoid duplication MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When compiling with Microsoft Visual Studio 2019, the compiler emits: …\lib\cgraph\strcasecmp.h(12,64): warning C4211: nonstandard extension used: redefined extern to static Investigation reveals libgd defines their own `strcasecmp` shim in gd.h: /* VS2012+ disable keyword macroizing unless _ALLOW_KEYWORD_MACROS is set We define inline, and strcasecmp if they're missing */ #ifdef _MSC_VER # define _ALLOW_KEYWORD_MACROS # ifndef inline # define inline __inline # endif # ifndef strcasecmp # define strcasecmp _stricmp # endif #endif To avoid this warning, guard Graphviz’ shim so it is only used when the libgd shim is not in use. Note that this also explains why MSVC is able to compile diffimg.c despite the Graphviz shim file not being included. --- lib/cgraph/strcasecmp.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/cgraph/strcasecmp.h b/lib/cgraph/strcasecmp.h index 78654feb7..f8e628385 100644 --- a/lib/cgraph/strcasecmp.h +++ b/lib/cgraph/strcasecmp.h @@ -9,9 +9,13 @@ #include + // some third-party libraries like libgd provide their own macro-based + // `strcasecmp` shim, so only define our own if their’s is not in scope +#ifndef strcasecmp static inline int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1, s2); } +#endif static inline int strncasecmp(const char *s1, const char *s2, size_t n) { return _strnicmp(s1, s2, n); -- 2.40.0