Fix building and using the library with MinGW -std=c++{98,11} options.

These options enable "strict ANSI" mode in MinGW which omits declarations of
POSIX functions from the standard headers. To allow the library and, possibly
even more importantly, the user code including our headers, to compile with
these options, declare the functions that we need ourselves.

This might appear to go against the spirit of "strict ANSI" mode, but the only
alternative would be to not use such functions at all and silently cripple the
library when -std=c++NN is used, compared to -std=g++NN case, and this doesn't
seem appealing neither.

Closes #16984.
This commit is contained in:
Vadim Zeitlin
2015-06-12 17:43:33 +02:00
parent e2410de134
commit aa30a2f97a
10 changed files with 99 additions and 3 deletions

View File

@@ -90,6 +90,8 @@
#define HAVE_WGETCWD
#endif
wxDECL_FOR_STRICT_MINGW32(int, _fileno, (FILE*))
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

View File

@@ -22,6 +22,23 @@
#pragma hdrstop
#endif
// This is a horrible hack which only works because we don't currently include
// <time.h> from wx/wxprec.h. It is needed because we need timezone-related
// stuff from MinGW time.h, but it is not compiled in strict ANSI mode and it
// is too complicated to be dealt with using wxDECL_FOR_STRICT_MINGW32(). So we
// just include the header after undefining __STRICT_ANSI__ to get all the
// declarations we need -- and then define it back to avoid inconsistencies in
// all our other headers.
//
// Note that the same hack is used for "environ" in utilscmn.cpp, so if the
// code here is modified because this hack becomes unnecessary or a better
// solution is found, the code there should be updated as well.
#ifdef wxNEEDS_STRICT_ANSI_WORKAROUNDS
#undef __STRICT_ANSI__
#include <time.h>
#define __STRICT_ANSI__
#endif
#include "wx/time.h"
#ifndef WX_PRECOMP

View File

@@ -23,6 +23,14 @@
#pragma hdrstop
#endif
// See comment about this hack in time.cpp: here we do it for environ external
// variable which can't be easily declared when using MinGW in strict ANSI mode.
#ifdef wxNEEDS_STRICT_ANSI_WORKAROUNDS
#undef __STRICT_ANSI__
#include <stdlib.h>
#define __STRICT_ANSI__
#endif
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/string.h"

View File

@@ -73,6 +73,10 @@
#include <xlocale.h>
#endif
wxDECL_FOR_STRICT_MINGW32(int, vswprintf, (wchar_t*, const wchar_t*, __VALIST));
wxDECL_FOR_STRICT_MINGW32(int, _putws, (const wchar_t*));
wxDECL_FOR_STRICT_MINGW32(void, _wperror, (const wchar_t*));
WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n)
{
// assume that we have mbsrtowcs() too if we have wcsrtombs()