Create the Windows portability header
authorChristopher Dykes <cdykes@fb.com>
Sat, 5 Mar 2016 01:55:27 +0000 (17:55 -0800)
committerFacebook Github Bot 2 <facebook-github-bot-2-bot@fb.com>
Sat, 5 Mar 2016 02:05:20 +0000 (18:05 -0800)
Summary: Because Windows' defines seem to get in the way more than they help.

Reviewed By: yfeldblum

Differential Revision: D2989507

fb-gh-sync-id: 148f390ef6adf977bffa2262aa76839b2bf4f507
shipit-source-id: 148f390ef6adf977bffa2262aa76839b2bf4f507

folly/Makefile.am
folly/portability/Windows.h [new file with mode: 0755]

index a66816e3e55235481aefd52b09f79680fc5b1aad..70de07e0da0c3b4940235d877d08ae04e1f74635 100644 (file)
@@ -276,6 +276,7 @@ nobase_follyinclude_HEADERS = \
        portability/SysTypes.h \
        portability/SysUio.h \
        portability/Time.h \
+       portability/Windows.h \
        Preprocessor.h \
        ProducerConsumerQueue.h \
        Random.h \
diff --git a/folly/portability/Windows.h b/folly/portability/Windows.h
new file mode 100755 (executable)
index 0000000..3b48858
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+// Only do anything if we are on windows.
+#ifdef _WIN32
+// This header is intended to be used in-place of including <Windows.h>,
+// <WinSock2.h>, <io.h> or <direct.h>.
+// It includes all of them, and undefines certain names defined by them that
+// are used in places in Folly.
+//
+// These have to be this way because we define our own versions
+// of close(), because the normal Windows versions don't handle
+// sockets at all.
+#ifndef __STDC__
+/* nolint */
+#define __STDC__ 1
+#include <io.h> // nolint
+#include <direct.h> // nolint
+#undef __STDC__
+#else
+#include <io.h> // nolint
+#include <direct.h> // nolint
+#endif
+
+#include <Windows.h>
+#include <WinSock2.h>
+
+#ifdef CAL_GREGORIAN
+#undef CAL_GREGORIAN
+#endif
+
+// Defined in winnt.h
+#ifdef DELETE
+#undef DELETE
+#endif
+
+// Defined in the GDI interface.
+#ifdef ERROR
+#undef ERROR
+#endif
+
+// Defined in minwindef.h
+#ifdef IN
+#undef IN
+#endif
+
+// Defined in winerror.h
+#ifdef NO_ERROR
+#undef NO_ERROR
+#endif
+
+// Defined in minwindef.h
+#ifdef OUT
+#undef OUT
+#endif
+
+// Defined in minwindef.h
+#ifdef STRICT
+#undef STRICT
+#endif
+
+// Defined in Winbase.h
+#ifdef Yield
+#undef Yield
+#endif
+
+#endif