[libcxx-commits] [PATCH] D79784: [libc++] Adjust how we guard the inclusion of unistd.h
John Brawn via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 12 07:29:59 PDT 2020
john.brawn created this revision.
john.brawn added reviewers: LittleFox94, ldionne.
Herald added subscribers: phosek, dexonsmith.
Herald added a project: libc++.
Herald added a reviewer: libc++.
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 moving the include guard for unistd.h in thread.cpp to __config to define _LIBCPP_HAS_UNISTD and use that, though in filesystem/operations.cpp we already unconditionally include it so just remove the extra include.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79784
Files:
libcxx/include/__config
libcxx/src/chrono.cpp
libcxx/src/filesystem/operations.cpp
libcxx/src/thread.cpp
Index: libcxx/src/thread.cpp
===================================================================
--- libcxx/src/thread.cpp
+++ 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 defined(_LIBCPP_HAS_UNISTD)
+#include <unistd.h>
+#endif
#if defined(__NetBSD__)
#pragma weak pthread_create // Do not create libpthread dependency
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ 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
Index: libcxx/src/chrono.cpp
===================================================================
--- libcxx/src/chrono.cpp
+++ 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 defined(_LIBCPP_HAS_UNISTD)
#include <unistd.h>
#endif
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -1552,6 +1552,10 @@
#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
#endif
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
+#define _LIBCPP_HAS_UNISTD
+#endif
+
#endif // __cplusplus
#endif // _LIBCPP_CONFIG
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79784.263423.patch
Type: text/x-patch
Size: 1938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200512/13f9ece0/attachment.bin>
More information about the libcxx-commits
mailing list