[vcpkg] fix extern C around ctermid
Additionally, move the system_header invocations to their own header file,
<vcpkg/base/system_header.h>
MODIFY
include/pch.h
include/pch.h
#pragma once
#include <vcpkg/base/pragmas.h>
+#include <vcpkg/base/system_headers.h>
#if defined(_WIN32)
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-
-#pragma warning(suppress : 4768)
-#include <windows.h>
-
-#pragma warning(suppress : 4768)
-#include <Shlobj.h>
-
#include <process.h>
#include <shellapi.h>
#include <winhttp.h>
-#else
-#include <unistd.h>
#endif
#include <algorithm>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
-#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <cstring>
+
#if VCPKG_USE_STD_FILESYSTEM
#include <filesystem>
#else
+#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#endif
+
#include <fstream>
#include <functional>
#include <iomanip>
#include <sys/time.h>
#endif
-#include <sys/types.h>
-// glibc defines major and minor in sys/types.h, and should not
-#undef major
-#undef minor
-
#include <system_error>
#include <thread>
#include <time.h>

MODIFY
include/vcpkg-test/util.h
include/vcpkg-test/util.h
+#include <vcpkg/base/system_headers.h>
+
#include <catch2/catch.hpp>
#include <vcpkg/base/pragmas.h>

ADD
include/vcpkg/base/system_headers.h
+#pragma once
+
+#if defined(_WIN32)
+
+#define NOMINMAX
+#define WIN32_LEAN_AND_MEAN
+
+#pragma warning(suppress : 4768)
+#include <windows.h>
+
+#pragma warning(suppress : 4768)
+#include <Shlobj.h>
+
+#else // ^^^^ Windows / Unix vvvv
+
+// 2020-05-19: workaround for a c standard library bug
+// ctermid is not behind an `extern "C"` barrier, so it's linked incorrectly.
+// This has been reported; remove it after 2023-05-19
+#if __APPLE__
+extern "C" {
+#endif
+
+#include <unistd.h>
+
+#if __APPLE__
+}
+#endif
+
+#endif
+
+#include <sys/types.h>
+// glibc defines major and minor in sys/types.h, and should not
+#undef major
+#undef minor
+

MODIFY
src/vcpkg-test/system.cpp
src/vcpkg-test/system.cpp
-#define _POSIX_C_SOURCE 200112L
+#include <vcpkg/base/system_headers.h>
#include <catch2/catch.hpp>
#include <string>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.h>
-#if defined(_WIN32)
-#define _NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#else
-#include <stdlib.h>
-#endif
-
using vcpkg::Optional;
using vcpkg::StringView;
using vcpkg::ZStringView;

MODIFY
src/vcpkg-test/util.cpp
src/vcpkg-test/util.cpp
+#include <vcpkg/base/system_headers.h>
+
#include <catch2/catch.hpp>
#include <vcpkg-test/util.h>
#define FILESYSTEM_SYMLINK_UNIX 1
#define FILESYSTEM_SYMLINK_NONE 2
-#if defined(__cpp_lib_filesystem)
+#if VCPKG_USE_STD_FILESYSTEM
#define FILESYSTEM_SYMLINK FILESYSTEM_SYMLINK_STD
-#include <filesystem> // required for filesystem::create_{directory_}symlink
#elif !defined(_MSC_VER)
#define FILESYSTEM_SYMLINK FILESYSTEM_SYMLINK_UNIX
-#include <unistd.h>
#else
@@ -169,10 +169,10 @@ namespace vcpkg::Test
#if FILESYSTEM_SYMLINK == FILESYSTEM_SYMLINK_STD
if (can_create_symlinks())
{
- std::filesystem::path targetp = target.native();
- std::filesystem::path filep = file.native();
+ fs::path targetp = target.native();
+ fs::path filep = file.native();
- std::filesystem::create_symlink(targetp, filep, ec);
+ fs::stdfs::create_symlink(targetp, filep, ec);
}
else
{

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
#include <vcpkg/base/pragmas.h>
-#if defined(_WIN32)
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-
-#pragma warning(push)
-#pragma warning(disable : 4768)
-#include <ShlObj.h>
-#pragma warning(pop)
-#else
-#include <unistd.h>
-#endif
+#include <vcpkg/base/system_headers.h>
#include <vcpkg/base/chrono.h>
#include <vcpkg/base/files.h>

MODIFY
src/vcpkg/base/files.cpp
src/vcpkg/base/files.cpp
#if !defined(_WIN32)
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif // ^^^ !defined(_WIN32)
+#endif
+
#if defined(__linux__)
#include <sys/sendfile.h>
#elif defined(__APPLE__)

MODIFY
src/vcpkgmetricsuploader.cpp
src/vcpkgmetricsuploader.cpp
#include <vcpkg/base/checks.h>
#include <vcpkg/base/files.h>
-#include <Windows.h>
+#include <vcpkg/base/system_headers.h>
+#include <shellapi.h>
using namespace vcpkg;

[vcpkg] fix extern C around ctermid (#11343)

Additionally, move the system_header invocations to their own header file,
<vcpkg/base/system_header.h>