[libc-commits] [PATCH] D150026: [libc] Use Linux errno and signal strings for Fuchsia

Roland McGrath via Phabricator via libc-commits libc-commits at lists.llvm.org
Sat May 6 02:12:36 PDT 2023


mcgrathr created this revision.
mcgrathr added reviewers: abrachet, Caslyn.
Herald added subscribers: libc-commits, ecnelises, phosek, tschuett, krytarowski.
Herald added projects: libc-project, All.
mcgrathr requested review of this revision.

The exact set of supported values is determined by the <errno.h>
and <signal.h> headers, which don't (yet) come from llvm-libc on
Fuchsia. The mappings of SIG* and E* codes to psignal/strsignal
and perror/strerror text used in Fuchsia libc today is the same
as for Linux.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150026

Files:
  libc/src/__support/StringUtil/tables/error_table.h
  libc/src/__support/StringUtil/tables/signal_table.h


Index: libc/src/__support/StringUtil/tables/signal_table.h
===================================================================
--- libc/src/__support/StringUtil/tables/signal_table.h
+++ libc/src/__support/StringUtil/tables/signal_table.h
@@ -14,18 +14,25 @@
 #include "posix_signal_table.h"
 #include "stdc_signal_table.h"
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__Fuchsia__)
+#define USE_LINUX_PLATFORM_SIGNALS 1
+#else
+#define USE_LINUX_PLATFORM_SIGNALS 0
+#endif
+
+#if USE_LINUX_PLATFORM_SIGNALS
 #include "linux/signal_table.h"
 #endif
 
 namespace __llvm_libc::internal {
 
-#ifdef __linux__
-inline constexpr auto PLATFORM_SIGNALS =
-    STDC_SIGNALS + POSIX_SIGNALS + LINUX_SIGNALS;
-#else
-inline constexpr auto PLATFORM_SIGNALS = STDC_SIGNALS;
-#endif
+inline constexpr auto PLATFORM_SIGNALS = []() {
+  if constexpr (USE_LINUX_PLATFORM_SIGNALS) {
+    return STDC_SIGNALS + POSIX_SIGNALS + LINUX_SIGNALS;
+  } else {
+    return STDC_SIGNALS;
+  }
+}();
 
 } // namespace __llvm_libc::internal
 
Index: libc/src/__support/StringUtil/tables/error_table.h
===================================================================
--- libc/src/__support/StringUtil/tables/error_table.h
+++ libc/src/__support/StringUtil/tables/error_table.h
@@ -14,18 +14,25 @@
 #include "posix_error_table.h"
 #include "stdc_error_table.h"
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__Fuchsia__)
+#define USE_LINUX_PLATFORM_ERRORS 1
+#else
+#define USE_LINUX_PLATFORM_ERRORS 0
+#endif
+
+#if USE_LINUX_PLATFORM_ERRORS
 #include "linux/error_table.h"
 #endif
 
 namespace __llvm_libc::internal {
 
-#ifdef __linux__
-inline constexpr auto PLATFORM_ERRORS =
-    STDC_ERRORS + POSIX_ERRORS + LINUX_ERRORS;
-#else
-inline constexpr auto PLATFORM_ERRORS = STDC_ERRORS;
-#endif
+inline constexpr auto PLATFORM_ERRORS = []() {
+  if constexpr (USE_LINUX_PLATFORM_ERRORS) {
+    return STDC_ERRORS + POSIX_ERRORS + LINUX_ERRORS;
+  } else {
+    return STDC_ERRORS;
+  }
+}();
 
 } // namespace __llvm_libc::internal
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150026.520050.patch
Type: text/x-patch
Size: 2027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230506/aa418ecf/attachment-0001.bin>


More information about the libc-commits mailing list