From: Christopher Dykes Date: Sat, 19 Nov 2016 01:54:36 +0000 (-0800) Subject: Don't attempt to separately close the underlying file descriptor in the format other... X-Git-Tag: v2016.11.21.00~3 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=bf44ef993a2db0bc76af0fa2ded445d09d99043f;p=folly.git 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 --- 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);