diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-26 21:39:46 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-03 07:58:52 -0600 |
commit | d419f42dd3f3635fc036413258ed530676998191 (patch) | |
tree | 63b46767bc2a7a0211eb9923b6e07a9fc95c7594 /gdb/xml-support.c | |
parent | 4a2b031d5452226cf7894f313b3aac603f7ec5fb (diff) | |
download | gdb-d419f42dd3f3635fc036413258ed530676998191.zip gdb-d419f42dd3f3635fc036413258ed530676998191.tar.gz gdb-d419f42dd3f3635fc036413258ed530676998191.tar.bz2 |
Introduce and use gdb_file_up
This introduces gdb_file_up, a unique pointer holding a FILE*, and
then changes some code in gdb to use it. In particular
gdb_fopen_cloexec now returns a gdb_file_up. This allow removing some
cleanups.
ChangeLog
2017-08-03 Tom Tromey <tom@tromey.com>
* xml-support.c (xml_fetch_content_from_file): Update.
* ui-file.c (stdio_file::open): Update.
* tracefile-tfile.c (tfile_start): Update.
* remote.c (remote_file_put, remote_file_get): Update.
* nat/linux-procfs.c (linux_proc_get_int)
(linux_proc_pid_get_state, linux_proc_tid_get_name): Update.
* nat/linux-osdata.c (linux_common_core_of_thread): Update.
(command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus)
(print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem)
(linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update.
* nat/linux-btrace.c (linux_determine_kernel_start): Update.
* linux-nat.c (linux_proc_pending_signals): Update.
* dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up.
(file_closer): Remove.
* compile/compile.c (compile_to_object): Update.
* common/filestuff.h (struct gdb_file_deleter): New.
(gdb_file_up): New typedef.
(gdb_fopen_cloexec): Change return type.
* common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up.
* cli/cli-dump.c (fopen_with_cleanup): Remove.
(dump_binary_file, restore_binary_file): Update.
* auto-load.c (auto_load_objfile_script_1): Update.
Diffstat (limited to 'gdb/xml-support.c')
-rw-r--r-- | gdb/xml-support.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/gdb/xml-support.c b/gdb/xml-support.c index fff3997..65638b9 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -1001,7 +1001,7 @@ char * xml_fetch_content_from_file (const char *filename, void *baton) { const char *dirname = (const char *) baton; - FILE *file; + gdb_file_up file; struct cleanup *back_to; char *text; size_t len, offset; @@ -1021,21 +1021,19 @@ xml_fetch_content_from_file (const char *filename, void *baton) if (file == NULL) return NULL; - back_to = make_cleanup_fclose (file); - /* Read in the whole file, one chunk at a time. */ len = 4096; offset = 0; text = (char *) xmalloc (len); - make_cleanup (free_current_contents, &text); + back_to = make_cleanup (free_current_contents, &text); while (1) { size_t bytes_read; /* Continue reading where the last read left off. Leave at least one byte so that we can NUL-terminate the result. */ - bytes_read = fread (text + offset, 1, len - offset - 1, file); - if (ferror (file)) + bytes_read = fread (text + offset, 1, len - offset - 1, file.get ()); + if (ferror (file.get ())) { warning (_("Read error from \"%s\""), filename); do_cleanups (back_to); @@ -1044,14 +1042,13 @@ xml_fetch_content_from_file (const char *filename, void *baton) offset += bytes_read; - if (feof (file)) + if (feof (file.get ())) break; len = len * 2; text = (char *) xrealloc (text, len); } - fclose (file); discard_cleanups (back_to); text[offset] = '\0'; |