[PATCH v2 2/5] Don't reset errno/bfd_error on 'throw_perror_with_name'

Sergio Durigan Junior
2020-03-17T15:47:28Z

Even though this patch is not necessarily needed by the main feature,
I think it's a good idea to have it.

We currently have this code on 'throw_perror_with_name':

/* I understand setting these is a matter of taste. Still, some people
may clear errno but not know about bfd_error. Doing this here is not
unreasonable. */
bfd_set_error (bfd_error_no_error);
errno = 0;

git blame tells me that this piece of code is pretty old; the commit
that "introduced" it is:

commit c906108c21474dfb4ed285bcc0ac6fe02cd400cc
Author: Stan Shebs <shebs@codesourcery.com>
Date: Fri Apr 16 01:35:26 1999 +0000

Initial creation of sourceware repository

so yeah...

If we go to the POSIX specification for 'perror', it doesn't really
say anything about whether errno should be preserved or not. It does,
however, say that 'perror's messages should be the same as those
returned by 'strerror', and 'strerror' is not supposed to alter errno
if the call is successful.

Maybe when our wrapper was written it was OK to modify errno, I don't
know. But I'd like to propose that we stick to POSIX in this case.

gdb/ChangeLog:
yyyy-mm-dd Sergio Durigan Junior <sergiodj@redhat.com>

* utils.c (throw_perror_with_name): Don't reset
errno/bfd_error.
---
gdb/utils.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index 0b470120a2..df8add1afa 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -595,12 +595,6 @@ throw_perror_with_name (enum errors errcode, const char *string)
{
std::string combined = perror_string (string);

- /* I understand setting these is a matter of taste. Still, some people
- may clear errno but not know about bfd_error. Doing this here is not
- unreasonable. */
- bfd_set_error (bfd_error_no_error);
- errno = 0;
-
throw_error (errcode, _("%s."), combined.c_str ());
}

--
2.24.1