[libc-commits] [libc] 46b76a5 - [libc] Use Linux errno and signal strings for Fuchsia

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Sun May 7 17:22:32 PDT 2023


Author: Roland McGrath
Date: 2023-05-07T17:22:21-07:00
New Revision: 46b76a54e16ac72e1c9769ce5b55774fbaaaaee2

URL: https://github.com/llvm/llvm-project/commit/46b76a54e16ac72e1c9769ce5b55774fbaaaaee2
DIFF: https://github.com/llvm/llvm-project/commit/46b76a54e16ac72e1c9769ce5b55774fbaaaaee2.diff

LOG: [libc] Use Linux errno and signal strings for Fuchsia

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.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D150026

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/StringUtil/tables/error_table.h b/libc/src/__support/StringUtil/tables/error_table.h
index 78f58bc43d6a9..5e8226e7d390b 100644
--- a/libc/src/__support/StringUtil/tables/error_table.h
+++ b/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
 

diff  --git a/libc/src/__support/StringUtil/tables/signal_table.h b/libc/src/__support/StringUtil/tables/signal_table.h
index b1b738abbac4a..8ee8aa274813d 100644
--- a/libc/src/__support/StringUtil/tables/signal_table.h
+++ b/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
 


        


More information about the libc-commits mailing list