]> granicus.if.org Git - icu/commitdiff
ICU-22002 Don't undef __STRICT_ANSI__
authorPaul Harris <harris.pc@gmail.com>
Thu, 16 Jun 2022 02:47:21 +0000 (10:47 +0800)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Thu, 23 Jun 2022 18:55:06 +0000 (11:55 -0700)
icu4c/source/io/ufile.cpp

index 607601935cf4c500fb86e98675a24ca6da592f8f..685f49043729d720d8dc439c9c4b27b5e1ef895d 100644 (file)
 */
 
 #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 <string> 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"
 #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