summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorÉrico Rolim <erico.erc@gmail.com>2021-02-01 21:16:56 -0300
committerMark Wielaard <mark@klomp.org>2021-02-05 15:36:25 +0100
commit8db222e36ae777e6aec8c61c616838a86258e99f (patch)
treee626106aa1745aabfb1df3a135f4dcf24caf8aa3 /libdwfl
parenttests: use ${CC} instead of 'gcc' in tests (diff)
downloadelfutils-8db222e36ae777e6aec8c61c616838a86258e99f.tar.gz
elfutils-8db222e36ae777e6aec8c61c616838a86258e99f.tar.bz2
elfutils-8db222e36ae777e6aec8c61c616838a86258e99f.tar.xz
libdwfl: use GNU strerror_r only when available.
Some C libraries don't provide the GNU version of strerror_r, only the XSI-compliant one. We use the GNU version when available, since it fits the code better, and otherwise use the XSI-compliant one. https://sourceware.org/bugzilla/show_bug.cgi?id=21010 Signed-off-by: Érico Rolim <erico.erc@gmail.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog4
-rw-r--r--libdwfl/dwfl_error.c17
2 files changed, 20 insertions, 1 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 5058f5f8..d107e78f 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
12021-02-01 Érico Nogueira <ericonr@disroot.org>
2
3 * dwfl_error.c (strerror_r): Only use the GNU version when available.
4
12021-01-08 Timm Bäder <tbaeder@redhat.com> 52021-01-08 Timm Bäder <tbaeder@redhat.com>
2 6
3 * elf-from-memory.c (elf_from_remote_memory): Add for loop over 7 * elf-from-memory.c (elf_from_remote_memory): Add for loop over
diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
index 7bcf61cc..a5c683a9 100644
--- a/libdwfl/dwfl_error.c
+++ b/libdwfl/dwfl_error.c
@@ -137,6 +137,21 @@ __libdwfl_seterrno (Dwfl_Error error)
137} 137}
138 138
139 139
140static const char *
141errnomsg(int error)
142{
143 /* Won't be changed by strerror_r, but not const so compiler doesn't throw warning */
144 static char unknown[] = "unknown error";
145
146#ifdef STRERROR_R_CHAR_P
147 return strerror_r (error, unknown, 0);
148#else
149 /* To store the error message from strerror_r in a thread-safe manner */
150 static __thread char msg[128];
151 return strerror_r (error, msg, sizeof (msg)) ? unknown : msg;
152#endif
153}
154
140const char * 155const char *
141dwfl_errmsg (int error) 156dwfl_errmsg (int error)
142{ 157{
@@ -154,7 +169,7 @@ dwfl_errmsg (int error)
154 switch (error &~ 0xffff) 169 switch (error &~ 0xffff)
155 { 170 {
156 case OTHER_ERROR (ERRNO): 171 case OTHER_ERROR (ERRNO):
157 return strerror_r (error & 0xffff, "bad", 0); 172 return errnomsg (error & 0xffff);
158 case OTHER_ERROR (LIBELF): 173 case OTHER_ERROR (LIBELF):
159 return elf_errmsg (error & 0xffff); 174 return elf_errmsg (error & 0xffff);
160 case OTHER_ERROR (LIBDW): 175 case OTHER_ERROR (LIBDW):