From 40dfb28b56fe55a370a35495e0f1eb6c95110f35 Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Thu, 9 Feb 2023 20:28:20 -0500 Subject: Move implementation of perror_with_name to gdbsupport gdbsupport/errors.h declares perror_with_name and leaves the implementation to the clients. However gdb and gdbserver's implementations are essentially the same, resulting in unnecessary code duplication. Fix this by implementing perror_with_name in gdbsupport. Add an optional parameter for specifying the errno used to generate the error message. Also move the implementation of perror_string to gdbsupport since perror_with_name requires it. Approved-By: Tom Tromey --- gdbserver/utils.cc | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'gdbserver/utils.cc') diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc index a6f5bd7..511364c 100644 --- a/gdbserver/utils.cc +++ b/gdbserver/utils.cc @@ -51,28 +51,6 @@ malloc_failure (long size) abort_or_exit (); } -/* Print the system error message for errno, and also mention STRING - as the file name for which the error was encountered. - Then return to command level. */ - -void -perror_with_name (const char *string) -{ - const char *err; - char *combined; - - err = safe_strerror (errno); - if (err == NULL) - err = "unknown error"; - - combined = (char *) alloca (strlen (err) + strlen (string) + 3); - strcpy (combined, string); - strcat (combined, ": "); - strcat (combined, err); - - error ("%s.", combined); -} - /* Print an error message and return to top level. */ void -- cgit v1.1