Skip to content

Commit

Permalink
eal/windows: fix debug build with MinGW
Browse files Browse the repository at this point in the history
Compiling with MinGW in --buildtype=debug produces a redefinition
error for strncasecmp.

The root cause is that rte_os.h shouldn't be injecting POSIX definitions
into the environment.  It is the applications responsibility to decide
how to handle missing functionality.

Resolving this properly will require further work, but in the meantime
wrap all such definitions with #ifndef/#endif.  This resolves the specific
issue with strncasecmp and handles similar issues that applications may
encounter.

Fixes: e8428a9 ("eal/windows: add some basic functions and macros")
Cc: stable@dpdk.org

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Committed-by: Thomas Monjalon <thomas@monjalon.net>
Commit-Id: a728832
Change-Id: I3ce584726d9eb1d9a9fc38ad215540f7f433fdde
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/dpdk/+/7079
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: Jim Harris <james.r.harris@intel.com>
  • Loading branch information
nconnolly1 authored and jimharris committed Apr 21, 2021
1 parent 3f84d84 commit eb16786
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/librte_eal/windows/include/rte_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,42 @@ extern "C" {
#define PATH_MAX _MAX_PATH
#endif

#ifndef sleep
#define sleep(x) Sleep(1000 * (x))
#endif

#ifndef strerror_r
#define strerror_r(a, b, c) strerror_s(b, c, a)
#endif

#ifndef strdup
/* strdup is deprecated in Microsoft libc and _strdup is preferred */
#define strdup(str) _strdup(str)
#endif

#ifndef strtok_r
#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
#endif

#ifndef index
#define index(a, b) strchr(a, b)
#endif

#ifndef rindex
#define rindex(a, b) strrchr(a, b)
#endif

#ifndef strncasecmp
#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
#endif

#ifndef close
#define close _close
#endif

#ifndef unlink
#define unlink _unlink
#endif

/* cpu_set macros implementation */
#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
Expand Down Expand Up @@ -89,7 +109,9 @@ eal_strerror(int code)
return buffer;
}

#ifndef strerror
#define strerror eal_strerror
#endif

#endif /* RTE_TOOLCHAIN_GCC */

Expand Down

0 comments on commit eb16786

Please sign in to comment.