[libcxx-commits] [libcxx] 4d25f44 - [libc++] Adjust how we guard the inclusion of unistd.h
John Brawn via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 14 03:58:48 PDT 2020
Author: John Brawn
Date: 2020-05-14T11:53:12+01:00
New Revision: 4d25f4453d60dee522e905c844dde0f4b6ed9475
URL: https://github.com/llvm/llvm-project/commit/4d25f4453d60dee522e905c844dde0f4b6ed9475
DIFF: https://github.com/llvm/llvm-project/commit/4d25f4453d60dee522e905c844dde0f4b6ed9475.diff
LOG: [libc++] Adjust how we guard the inclusion of unistd.h
unistd.h isn't guaranteed to exist when the target isn't Windows, in
particular if the target is bare-metal (i.e. no operating system).
Handle this by using __has_include instead, though in
filesystem/operations.cpp we already unconditionally include it so
just remove the extra include.
Differential Revision: https://reviews.llvm.org/D79784
Added:
Modified:
libcxx/src/chrono.cpp
libcxx/src/filesystem/operations.cpp
libcxx/src/thread.cpp
Removed:
################################################################################
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 48c02c8d0682..a1a456faf2d3 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -12,7 +12,7 @@
#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
#include "include/apple_availability.h"
-#if !defined(_WIN32)
+#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 2c91ffd2df1d..51bd1ca51bf4 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -36,10 +36,6 @@
#define _LIBCPP_USE_COPYFILE
#endif
-#if !defined(_WIN32)
-#include <unistd.h>
-#endif
-
#if !defined(__APPLE__) && _POSIX_TIMERS > 0
#define _LIBCPP_USE_CLOCK_GETTIME
#endif
diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp
index c0bc1cbbbbc3..5f44e9e40fc7 100644
--- a/libcxx/src/thread.cpp
+++ b/libcxx/src/thread.cpp
@@ -23,9 +23,9 @@
# endif
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
-# include <unistd.h>
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
+#if __has_include(<unistd.h>)
+#include <unistd.h>
+#endif
#if defined(__NetBSD__)
#pragma weak pthread_create // Do not create libpthread dependency
More information about the libcxx-commits
mailing list