From: Paul Harris Date: Thu, 16 Jun 2022 02:47:21 +0000 (+0800) Subject: ICU-22002 Don't undef __STRICT_ANSI__ X-Git-Tag: cldr/2022-06-27~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86cc2b98cbf694074cfe951467cc373d26fa9df2;p=icu ICU-22002 Don't undef __STRICT_ANSI__ --- diff --git a/icu4c/source/io/ufile.cpp b/icu4c/source/io/ufile.cpp index 607601935cf..685f4904372 100644 --- a/icu4c/source/io/ufile.cpp +++ b/icu4c/source/io/ufile.cpp @@ -21,11 +21,18 @@ */ #include "unicode/platform.h" -#if defined(__GNUC__) && !defined(__clang__) && defined(__STRICT_ANSI__) -// g++, fileno isn't defined if __STRICT_ANSI__ is defined. -// clang fails to compile the header unless __STRICT_ANSI__ is defined. -// __GNUC__ is set by both gcc and clang. -#undef __STRICT_ANSI__ +#if U_PLATFORM == U_PF_CYGWIN && defined(__STRICT_ANSI__) +/* GCC on cygwin (not msys2) with -std=c++11 or newer has stopped defining fileno, + unless gcc extensions are enabled (-std=gnu11). + fileno is POSIX, but is not standard ANSI C. + It has always been a GCC extension, which everyone used until recently. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40278#c7 + + For cygwin/mingw, the FILE* pointer isn't opaque, so we can just use a simple macro. + Suggested fix from: https://github.com/gabime/spdlog/issues/1581#issuecomment-650323251 +*/ +#define _fileno(__F) ((__F)->_file) +#define fileno(__F) _fileno(__F) #endif #include "locmap.h" @@ -45,7 +52,10 @@ #include "cmemory.h" #if U_PLATFORM_USES_ONLY_WIN32_API && !defined(fileno) -/* Windows likes to rename Unix-like functions */ +/* We will just create an alias to Microsoft's implementation, + which is prefixed with _ as they deprecated non-ansi-standard POSIX function names. + https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-fileno?view=msvc-170 +*/ #define fileno _fileno #endif