aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-06-07 16:20:12 -0600
committerTom Tromey <tom@tromey.com>2018-06-09 16:09:52 -0600
commit77ad7394454c29cc7a4a865cd226491df457f6f6 (patch)
tree77bb9f15156be6ba0a314d35a11d2fb9c1247752 /gdb
parent191cca638351fcaf9bee93a396bd4f8b74f915eb (diff)
downloadgdb-77ad7394454c29cc7a4a865cd226491df457f6f6.zip
gdb-77ad7394454c29cc7a4a865cd226491df457f6f6.tar.gz
gdb-77ad7394454c29cc7a4a865cd226491df457f6f6.tar.bz2
Remove two more uses of make_cleanup_close
This removes two more uses of make_cleanup_close, replacing them with relatively straightforward uses of scoped_fd. Tested by the buildbot. gdb/ChangeLog 2018-06-09 Tom Tromey <tom@tromey.com> * source.c (reverse_search_command, forward_search_command): Use scoped_fd.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/source.c30
2 files changed, 17 insertions, 18 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5233704..1ff0e16 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2018-06-09 Tom Tromey <tom@tromey.com>
+ * source.c (reverse_search_command, forward_search_command): Use
+ scoped_fd.
+
+2018-06-09 Tom Tromey <tom@tromey.com>
+
* serial.c (serial_ops_p): Remove typedef. Don't declare VEC.
(serial_ops_list): Now static, std::vector.
(serial_interface_lookup, serial_add_interface): Update.
diff --git a/gdb/source.c b/gdb/source.c
index 5e50f42..cc5c46d 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1539,10 +1539,8 @@ static void
forward_search_command (const char *regex, int from_tty)
{
int c;
- int desc;
int line;
char *msg;
- struct cleanup *cleanups;
line = last_line_listed + 1;
@@ -1553,22 +1551,21 @@ forward_search_command (const char *regex, int from_tty)
if (current_source_symtab == 0)
select_source_symtab (0);
- desc = open_source_file (current_source_symtab);
- if (desc < 0)
+ scoped_fd desc (open_source_file (current_source_symtab));
+ if (desc.get () < 0)
perror_with_name (symtab_to_filename_for_display (current_source_symtab));
- cleanups = make_cleanup_close (desc);
if (current_source_symtab->line_charpos == 0)
- find_source_lines (current_source_symtab, desc);
+ find_source_lines (current_source_symtab, desc.get ());
if (line < 1 || line > current_source_symtab->nlines)
error (_("Expression not found"));
- if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
+ if (lseek (desc.get (), current_source_symtab->line_charpos[line - 1], 0)
+ < 0)
perror_with_name (symtab_to_filename_for_display (current_source_symtab));
- discard_cleanups (cleanups);
- gdb_file_up stream (fdopen (desc, FDOPEN_MODE));
+ gdb_file_up stream (fdopen (desc.release (), FDOPEN_MODE));
clearerr (stream.get ());
while (1)
{
@@ -1624,10 +1621,8 @@ static void
reverse_search_command (const char *regex, int from_tty)
{
int c;
- int desc;
int line;
char *msg;
- struct cleanup *cleanups;
line = last_line_listed - 1;
@@ -1638,22 +1633,21 @@ reverse_search_command (const char *regex, int from_tty)
if (current_source_symtab == 0)
select_source_symtab (0);
- desc = open_source_file (current_source_symtab);
- if (desc < 0)
+ scoped_fd desc (open_source_file (current_source_symtab));
+ if (desc.get () < 0)
perror_with_name (symtab_to_filename_for_display (current_source_symtab));
- cleanups = make_cleanup_close (desc);
if (current_source_symtab->line_charpos == 0)
- find_source_lines (current_source_symtab, desc);
+ find_source_lines (current_source_symtab, desc.get ());
if (line < 1 || line > current_source_symtab->nlines)
error (_("Expression not found"));
- if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0)
+ if (lseek (desc.get (), current_source_symtab->line_charpos[line - 1], 0)
+ < 0)
perror_with_name (symtab_to_filename_for_display (current_source_symtab));
- discard_cleanups (cleanups);
- gdb_file_up stream (fdopen (desc, FDOPEN_MODE));
+ gdb_file_up stream (fdopen (desc.release (), FDOPEN_MODE));
clearerr (stream.get ());
while (line > 1)
{