From bf44ef993a2db0bc76af0fa2ded445d09d99043f Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Fri, 18 Nov 2016 17:54:36 -0800 Subject: [PATCH] Don't attempt to separately close the underlying file descriptor in the format other test Summary: Windows automatically closes the underlying file descriptor when you call fclose, however fclose is not a function that can be easily overriden in the portability layer, so choose to just not call `close` on Windows instead. Reviewed By: yfeldblum Differential Revision: D4190524 fbshipit-source-id: a68edccd04e63f89c178ade584fa7192845773f8 --- folly/Portability.h | 6 ++++++ folly/test/FormatOtherTest.cpp | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/folly/Portability.h b/folly/Portability.h index 1ec55c10..77494f95 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -321,4 +321,10 @@ constexpr auto kIsLinux = true; #else constexpr auto kIsLinux = false; #endif + +#if defined(_WIN32) +constexpr auto kIsWindows = true; +#else +constexpr auto kIsWindows = false; +#endif } diff --git a/folly/test/FormatOtherTest.cpp b/folly/test/FormatOtherTest.cpp index 466d3c65..2882b7a0 100644 --- a/folly/test/FormatOtherTest.cpp +++ b/folly/test/FormatOtherTest.cpp @@ -20,10 +20,11 @@ #include #include +#include #include #include -#include #include +#include using namespace folly; @@ -33,7 +34,13 @@ TEST(FormatOther, file) { { int fds[2]; CHECK_ERR(pipe(fds)); - SCOPE_EXIT { closeNoInt(fds[1]); }; + SCOPE_EXIT { + // fclose on Windows automatically closes the underlying + // file descriptor. + if (!kIsWindows) { + closeNoInt(fds[1]); + } + }; { FILE* fp = fdopen(fds[1], "wb"); PCHECK(fp); -- 2.34.1