]> granicus.if.org Git - graphviz/commitdiff
cgraph: [nfc] guard 'strcasecmp' definition to avoid duplication
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Feb 2022 17:59:06 +0000 (09:59 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 20 Feb 2022 23:31:22 +0000 (15:31 -0800)
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

index 78654feb7edc05934a3cdad99f85b6407c983893..f8e62838597d767ebe2093091f2fbdf57e0d6bb2 100644 (file)
@@ -9,9 +9,13 @@
 
   #include <string.h>
 
+  // 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);