0001-errno-util-Make-STRERROR-portable-for-musl.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From f66b5c802ce0a3310f5580cfc1b02446f8087568 Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Mon, 23 Jan 2023 23:39:46 -0800
  4. Subject: [PATCH] errno-util: Make STRERROR portable for musl
  5. Sadly, systemd has decided to use yet another GNU extention in a macro
  6. lets make this such that we can use XSI compliant strerror_r() for
  7. non-glibc hosts
  8. Upstream-Status: Inappropriate [musl specific]
  9. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  10. ---
  11. src/basic/errno-util.h | 12 ++++++++++--
  12. 1 file changed, 10 insertions(+), 2 deletions(-)
  13. diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h
  14. index 091f99c590..eb5c1f9961 100644
  15. --- a/src/basic/errno-util.h
  16. +++ b/src/basic/errno-util.h
  17. @@ -14,8 +14,16 @@
  18. * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
  19. *
  20. * Note that we use the GNU variant of strerror_r() here. */
  21. -#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
  22. -
  23. +static inline const char * STRERROR(int errnum);
  24. +
  25. +static inline const char * STRERROR(int errnum) {
  26. +#ifdef __GLIBC__
  27. + return strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN);
  28. +#else
  29. + static __thread char buf[ERRNO_BUF_LEN];
  30. + return strerror_r(abs(errnum), buf, ERRNO_BUF_LEN) ? "unknown error" : buf;
  31. +#endif
  32. +}
  33. /* A helper to print an error message or message for functions that return 0 on EOF.
  34. * Note that we can't use ({ … }) to define a temporary variable, so errnum is
  35. * evaluated twice. */
  36. --
  37. 2.39.1