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
#else
constexpr auto kIsLinux = false;
#endif
#else
constexpr auto kIsLinux = false;
#endif
+
+#if defined(_WIN32)
+constexpr auto kIsWindows = true;
+#else
+constexpr auto kIsWindows = false;
+#endif
#include <folly/FBVector.h>
#include <folly/FileUtil.h>
#include <folly/FBVector.h>
#include <folly/FileUtil.h>
+#include <folly/Portability.h>
#include <folly/dynamic.h>
#include <folly/json.h>
#include <folly/dynamic.h>
#include <folly/json.h>
-#include <folly/small_vector.h>
#include <folly/portability/GTest.h>
#include <folly/portability/GTest.h>
+#include <folly/small_vector.h>
{
int fds[2];
CHECK_ERR(pipe(fds));
{
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);
{
FILE* fp = fdopen(fds[1], "wb");
PCHECK(fp);