diff options
Diffstat (limited to 'gdb/cli/cli-dump.c')
-rw-r--r-- | gdb/cli/cli-dump.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index d6d4aab..3d8d386 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -92,17 +92,6 @@ scan_filename_with_cleanup (const char **cmd, const char *defname) return fullname; } -static FILE * -fopen_with_cleanup (const char *filename, const char *mode) -{ - FILE *file = gdb_fopen_cloexec (filename, mode); - - if (file == NULL) - perror_with_name (filename); - make_cleanup_fclose (file); - return file; -} - static gdb_bfd_ref_ptr bfd_openr_or_error (const char *filename, const char *target) { @@ -168,11 +157,10 @@ static void dump_binary_file (const char *filename, const char *mode, const bfd_byte *buf, ULONGEST len) { - FILE *file; int status; - file = fopen_with_cleanup (filename, mode); - status = fwrite (buf, len, 1, file); + gdb_file_up file = gdb_fopen_cloexec (filename, mode); + status = fwrite (buf, len, 1, file.get ()); if (status != 1) perror_with_name (filename); } @@ -509,14 +497,13 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) static void restore_binary_file (const char *filename, struct callback_data *data) { - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); - FILE *file = fopen_with_cleanup (filename, FOPEN_RB); + gdb_file_up file = gdb_fopen_cloexec (filename, FOPEN_RB); long len; /* Get the file size for reading. */ - if (fseek (file, 0, SEEK_END) == 0) + if (fseek (file.get (), 0, SEEK_END) == 0) { - len = ftell (file); + len = ftell (file.get ()); if (len < 0) perror_with_name (filename); } @@ -541,12 +528,12 @@ restore_binary_file (const char *filename, struct callback_data *data) (unsigned long) (data->load_start + data->load_offset + len)); /* Now set the file pos to the requested load start pos. */ - if (fseek (file, data->load_start, SEEK_SET) != 0) + if (fseek (file.get (), data->load_start, SEEK_SET) != 0) perror_with_name (filename); /* Now allocate a buffer and read the file contents. */ gdb::byte_vector buf (len); - if (fread (buf.data (), 1, len, file) != len) + if (fread (buf.data (), 1, len, file.get ()) != len) perror_with_name (filename); /* Now write the buffer into target memory. */ @@ -554,7 +541,6 @@ restore_binary_file (const char *filename, struct callback_data *data) buf.data (), len); if (len != 0) warning (_("restore: memory write failed (%s)."), safe_strerror (len)); - do_cleanups (cleanup); } static void |