summaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2013-10-11 08:20:10 +0000
committerJoel Brobecker <brobecker@gnat.com>2013-10-11 08:20:10 +0000
commit0cf4063e29439cdf8693d2357ead6659c6defd74 (patch)
tree7918a5de515b9bf85e8c74f3e674c66f00d64b7c /gdb/utils.c
parentbb66bd5176cc5c47d44fdc693c0d6219425af5c5 (diff)
downloadbinutils-gdb-0cf4063e29439cdf8693d2357ead6659c6defd74.tar.gz
new function perror_string extracted out of throw_perror_with_name.
The main purpose of this patch is to extract the part of throw_perror_with_name that computes a string providing the system error message combined with a prefix string. This will become useful later on to provide a routine which prints a warning using that perror_string, rather than throwing an error. gdb/ChangeLog: * utils.c (perror_string): New function, extracted out of throw_perror_with_name. (throw_perror_with_name): Rework to use perror_string.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 26879ec3721..402fe8ee240 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -957,6 +957,26 @@ add_internal_problem_command (struct internal_problem *problem)
xfree (show_doc);
}
+/* Return a newly allocated string, containing the PREFIX followed
+ by the system error message for errno (separated by a colon).
+
+ The result must be deallocated after use. */
+
+static char *
+perror_string (const char *prefix)
+{
+ char *err;
+ char *combined;
+
+ err = safe_strerror (errno);
+ combined = (char *) xmalloc (strlen (err) + strlen (prefix) + 3);
+ strcpy (combined, prefix);
+ strcat (combined, ": ");
+ strcat (combined, err);
+
+ return combined;
+}
+
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered. Use ERRCODE
for the thrown exception. Then return to command level. */
@@ -964,14 +984,10 @@ add_internal_problem_command (struct internal_problem *problem)
void
throw_perror_with_name (enum errors errcode, const char *string)
{
- char *err;
char *combined;
- err = safe_strerror (errno);
- combined = (char *) alloca (strlen (err) + strlen (string) + 3);
- strcpy (combined, string);
- strcat (combined, ": ");
- strcat (combined, err);
+ combined = perror_string (string);
+ make_cleanup (xfree, combined);
/* 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