This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: MinGW compilation warnings in libiberty's xstrndup.c
- From: Eli Zaretskii <eliz at gnu dot org>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, gdb-patches at sourceware dot org, thomas at codesourcery dot com
- Date: Fri, 19 May 2017 18:40:12 +0300
- Subject: Re: MinGW compilation warnings in libiberty's xstrndup.c
- Authentication-results: sourceware.org; auth=none
- References: <83h90vcqo6.fsf@gnu.org> <60a354b0-6c1a-15ea-177a-8bdb198c8c03@redhat.com>
- Reply-to: Eli Zaretskii <eliz at gnu dot org>
> Cc: gdb-patches@sourceware.org, Thomas Schwinge <thomas@codesourcery.com>
> From: Pedro Alves <palves@redhat.com>
> Date: Fri, 19 May 2017 16:22:55 +0100
>
> But then, xstrndup.c has at the top:
>
> #ifdef HAVE_STRING_H
> #include <string.h>
> #else
> # ifdef HAVE_STRINGS_H
> # include <strings.h>
> # endif
> #endif
>
> So I would expect your build to pick the strnlen declaration from
> one of the string.h or strings.h mingw headers. Why didn't it?
Because MinGW doesn't have it, not unless you build a program that
will require one of the newer versions of the Windows C runtime
library. That's why libiberty's strnlen is being compiled in the
MinGW build in the first place.
Specifically, the MinGW headers do provide a prototype for strnlen if
the program defines __MSVCRT_VERSION__ to be a high enough version, or
defines _POSIX_C_SOURCE >= 200809L, but none of these is set by
default, and is not a good idea, as explained above, for a program
that needs to run on a wide variety of OS versions.
IOW, libiberty shouldn't rely on the system headers to provide a
strnlen prototype when libiberty's strnlen is being included in the
library as a replacement.